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

熱點內容
網路安全情況核查台賬是什麼 瀏覽:590
linuxwtmp查看 瀏覽:947
app掛號怎麼拿單 瀏覽:902
如何用手機編程出一個心形 瀏覽:934
蘋果不是原裝的數據線哪個好 瀏覽:471
不越獄多開應用程序 瀏覽:922
iphone4揚聲器壞了 瀏覽:106
銳捷網路校招筆試題 瀏覽:192
多可網路爬蟲軟體怎麼用 瀏覽:172
miui微信表情包在哪個文件夾 瀏覽:939
我的微信是不是別人看不到了 瀏覽:193
真實女友2安卓版 瀏覽:301
win81文件夾菜單 瀏覽:336
工作中編程看什麼書 瀏覽:9
未來數據科技有哪些書 瀏覽:243
電腦如何找迴文件 瀏覽:950
簡應用安卓 瀏覽:578
哪個數據准確表示股票價格 瀏覽:612
poi數據怎麼用 瀏覽:973
linux伺服器搭建php 瀏覽:993

友情鏈接