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

熱點內容
任命文件人字多少號 瀏覽:27
如何給桌面的文件自動填寫序號 瀏覽:349
壓縮文件JPG重命名 瀏覽:487
vivox7怎麼隱藏文件 瀏覽:340
官網買蘋果好處 瀏覽:153
直播app源碼如何搭建 瀏覽:31
c盤系統文件包介紹圖片 瀏覽:856
linuxopt主要存哪些文件 瀏覽:924
jsdate天數 瀏覽:930
qq空間怎樣發視頻文件在哪裡找 瀏覽:208
nrf2401收發程序 瀏覽:498
哪個網站看新聞最好 瀏覽:944
找到文件夾並清除linux 瀏覽:82
蘋果app不安全怎麼辦 瀏覽:1000
電腦桌面文件收集軟體推薦 瀏覽:317
桌面的文件夾不能刪除不了怎麼辦 瀏覽:724
什麼是手機溫控文件 瀏覽:840
廣東農信app怎麼更改預留手機號碼 瀏覽:241
cdm打開隱藏文件夾 瀏覽:320
貝殼app房子為什麼偶爾不顯示 瀏覽:4

友情鏈接