導航:首頁 > 編程語言 > java補零學號

java補零學號

發布時間:2023-09-21 02:06:42

『壹』 用java編寫根據學號信息找到學生並實現信息的修改

<pre t="code" l="java">//已成功運行通過可自己寫學號測試
public class test {
public static void main(String args[]) {
String s = "d344";
if(check(s))
System.out.println("學號正確");
else System.out.println("學號錯誤");
System.out.println("專業為:"+getmajor(s));
}

public static Boolean check(String s) {
Boolean t=true;
String s1=s.substring(0, 7);
String s2=s.substring(8, 11);
try{
Integer i=Integer.parseInt(s1);
Integer j=Integer.parseInt(s2);
}catch(Exception e){
t=false;
}

return t;

}

public static String getmajor(String s) {
return s.substring(5, 7);

}

}

『貳』 java編程中,從鍵盤輸入學號,然後輸出學號中百位百位數字是3的學號,輸入0時結束循環。

#include struct Student{ int num; char name[20]; float score[3], average;};int main(void){ int i, j; struct Student std[10] = {0}, temp; puts("Please enter information of student : "); for (i = 0; i < 10; ++i) { scanf("%d%s", &std[i].num, std[i].name); for (j = 0; j < 3; ++j) { scanf("%f", &std[i].score[j]); std[i].average += std[i].score[j]; } std[i].average /= 3; } for (i = 0; i < 9; ++i) { for (j = 0; j < 9 - i; ++j) { if (std[j].average < std[j + 1].average) { temp = std[j]; std[j] = std[j + 1]; std[j + 1] = temp; } } } for (i = 0; i < 10; ++i) { printf("Num=%d Name=%-6s ", std[i].num, std[i].name); printf("Score1=%0.2f Score2=%0.2f Score3=%0.2f ", std[i].score[0], std[i].score[1], std[i].score[2]); printf("Average=%0.2f\n", std[i].average); } return 0;}

『叄』 java的字元型數組補零

import java.util.Scanner;

public class T
{
public static void main(String[] args)
{
int n;
System.out.print("請輸入數組a的長專度屬:");
Scanner sc = new Scanner(System.in);
n=sc.nextInt();

char[] a = new char[n];
char[] b = new char[200];
for(int i=0;i<n;i++)
a[i]='1';
for (int i = 0; i < 200; i++)
b[i]='0';
for(int j=0;j<n;j++)
b[199-j]=a[j];
System.out.println(b);
}
}

『肆』 java中如何將數字轉化為字元串並且不足位數補0

具體操作如下:

String str1="1";

DecimalFormatdf=new DecimalFormat("0000");

String str2=df.format(Integer.parseInt(str1));

System.out.println(str2);

JAVA

閱讀全文

與java補零學號相關的資料

熱點內容
如何在手機里創建excel文件 瀏覽:172
電腦升級配置下載 瀏覽:44
蘋果系統鈴聲文件位置 瀏覽:663
又如何處理數據 瀏覽:44
文明5美麗新世界升級擋 瀏覽:30
數據源文件可以用什麼 瀏覽:614
fw文件找不到 瀏覽:192
蘋果沒法粘貼文件 瀏覽:643
rnn不能處理什麼數據 瀏覽:109
硬筆書法工具 瀏覽:357
文件的頭部和後部內容 瀏覽:917
50g的視頻文件刻錄大概多少錢 瀏覽:737
hbasejavaapi 瀏覽:983
cad每次關閉會自動保存一個文件 瀏覽:49
js點擊上滑下滑效果 瀏覽:191
怎樣在看過的pdf文件做標記 瀏覽:320
js數字轉時間 瀏覽:600
pdf文件不能在文件夾內預覽 瀏覽:837
angularjsapi中文 瀏覽:405
怎麼在兩個表格里找出相同的數據 瀏覽:650

友情鏈接