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

熱點內容
ps3文件分割視頻 瀏覽:280
微信圖片一鍵轉發軟體 瀏覽:331
如何判斷s200plc編程電纜 瀏覽:691
太原編程培訓班哪個好 瀏覽:171
樹葉吹奏教程 瀏覽:6
社交app帶來了哪些社會問題 瀏覽:394
如何安裝愛寶8800數據採集器 瀏覽:712
文件保存了怎麼找不到了 瀏覽:476
彩票網站怎麼辨真假 瀏覽:840
pr找不到該文件 瀏覽:963
java移除panel 瀏覽:354
jsp填充jsp 瀏覽:166
海關外貿大數據在哪裡查 瀏覽:381
思特奇java筆試題 瀏覽:121
葫蘆俠在手機中的文件名 瀏覽:813
plc編程應該怎麼收錢 瀏覽:584
c語言中源文件由什麼組成 瀏覽:890
linuxhttpdphp配置文件 瀏覽:607
拆單數據要怎麼保存 瀏覽:17
mac電腦怎樣壓縮文件到100m 瀏覽:645

友情鏈接