導航:首頁 > 編程語言 > 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補零學號相關的資料

熱點內容
文件系統壞了怎麼辦 瀏覽:261
小公司網路布線 瀏覽:515
怎麼用二維碼編程 瀏覽:341
f9b文件能用手機看嗎 瀏覽:364
手機暴風視頻文件夾 瀏覽:394
vsftpdlinux下載文件 瀏覽:948
文件名修改後快捷方式還可以用嗎 瀏覽:387
親密愛人qq相冊名字 瀏覽:884
怎麼修改手機原始密碼 瀏覽:230
榆次網站優化怎麼樣 瀏覽:537
vb窗體文件如何打開 瀏覽:810
百度找圖怎麼跳轉網站 瀏覽:284
安卓44如何隱藏文件夾 瀏覽:92
sr100怎麼編程序 瀏覽:795
蘋果手機怎樣保存信息 瀏覽:379
安卓patch是什麼文件 瀏覽:819
2003word審閱 瀏覽:387
手機時間查找新文件 瀏覽:695
資料庫管理員怎麼入行 瀏覽:852
安卓nba2k17修改能力 瀏覽:868

友情鏈接