資源描述:
《java經(jīng)典實用程序代碼》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫。
1、1百分制分?jǐn)?shù)到等級分?jǐn)?shù)packagepm;publicclassSwitchTest{//編寫程序,實現(xiàn)從百分制分?jǐn)?shù)到等級分?jǐn)?shù)的轉(zhuǎn)換////>=90A//80~89B//70~79C//60~69D//<60Epublicstaticvoidmain(String[]args){ints=87;switch(s/10){case10:System.out.println("A");break;case9:System.out.println("A");break;case8:System.out.println("B");break
2、;case7:System.out.println("c");break;case6:System.out.println("D");break;default:System.out.println("E");break;}}}2成法口訣陣形packagepm;publicclassSwitchTest{publicstaticvoidmain(String[]args){for(inti=1;i<=9;i++){for(intj=1;j<=i;j++){System.out.print(j+"*"+i+"="+(i*j)+"t"
3、);}System.out.println();}}}3華氏和攝氏的轉(zhuǎn)換法packagepm;importjava.util.Scanner;publicclassSwitchTest{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);while(true){System.out.println("請輸入要轉(zhuǎn)換的溫度類型:C或F");Strings=sc.next().trim();if("c".equalsIgnoreCase(s)){//做攝氏向
4、華攝的轉(zhuǎn)換System.out.println("請輸入要轉(zhuǎn)換攝氏的溫度:..");doubledb=sc.nextDouble();doubledb2=(db*9/5)+32;System.out.println("對應(yīng)的華氏溫度:"+db2+"F");}elseif("f".equalsIgnoreCase(s)){//做華攝向攝氏的轉(zhuǎn)換System.out.println("請輸入要轉(zhuǎn)換華氏的溫度:..");doubledb=sc.nextDouble();doubledb2=(db-32)*5/9;System.out.pr
5、intln("對應(yīng)的攝氏溫度:"+Math.round(db2)+"C");}elseif("exit".equalsIgnoreCase(s)){break;}}}}packagepm;importjava.util.Scanner;publicclassSwitchTest{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);booleanflag=true;while(flag){System.out.println("請輸入要轉(zhuǎn)換的溫度,如:5
6、0c或100f");Stringstr=sc.nextLine().trim();if(str.endsWith("c")
7、
8、str.endsWith("C")){//做攝氏向華攝的轉(zhuǎn)換30cStringst=str.substring(0,str.length()-1);doubledb=Double.parseDouble(st);//[0,2)//2doubledb=Double.valueOf(st).doubleValue();doubledb2=(db*9/5)+32;System.out.println("對應(yīng)的華氏溫
9、度:"+db2+"F");}elseif(str.endsWith("f")
10、
11、str.endsWith("F")){//做華攝向攝氏的轉(zhuǎn)換Stringst=str.substring(0,str.length()-1);doubledb=Double.parseDouble(st);//[0,2)//2doubledb=Double.valueOf(st).doubleValue();doubledb2=(db-32)*5/9;System.out.println("對應(yīng)的攝氏溫度:"+Math.round(db2)+"C");}
12、elseif("exit".equalsIgnoreCase(str)){flag=false;}}}}4三個數(shù)的最大數(shù)packagepm;publicclassSwitchTest{publicstaticvoidmain(Stri