資源描述:
《java 基礎(chǔ) 30題 __答案》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、1、從鍵盤輸入一個正整數(shù),按數(shù)字的相反順序輸出。packagecom.my.ccit;importjava.util.Scanner;publicclassa1{publicstaticvoidmain(String[]args){Scanners=newScanner(System.in);intm=s.nextInt();intsum=0;intn;while(m!=0){n=m%10;m=m/10;sum=sum*10+n;}System.out.println(sum);}}2、寫一條for語句,計數(shù)條件為n從100~200,步長為2;然后再用while語句實現(xiàn)同樣的
2、循環(huán)。packagecom.my.ccit;publicclassa2{publicstaticvoidmain(String[]args){intn;for(n=100;n<=200;n=n+2){System.out.println(n);}}otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWe
3、stNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand}3、編寫一段程序,運行時向用戶
4、提問“你考了多少分?(0~100)”,接受輸入后判斷其等級并顯示出來。判斷依據(jù)如下:等級={優(yōu)(90~100分);良(80~89分);中(60~69分);差(0~59分);}packagecom.my.ccit;importjava.util.Scanner;publicclassa3{publicstaticvoidmain(String[]args){Scanners=newScanner(System.in);intm=s.nextInt();if(m>=90&&m<=100){System.out.println("優(yōu)");}elseif(m>=80){System.
5、out.println("良");}elseif(m>=70){System.out.println("中");}elseif(m>=60){System.out.println("及格");}else{System.out.println("差");}}}4、使用for循環(huán)語句求出1~100之間的質(zhì)數(shù)。packagecom.my.ccit;publicclassa4{/***@paramargs*/publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodotherstaffoftheCentre.During
6、thewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,She
7、nmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersandstub4、使用for循環(huán)語句求出1~100之間的質(zhì)數(shù)。intn;intj;booleanflag=false;for(n=1;n<=100;n++){for(j=2;j<=n-1;j++){if(n%j==0){flag=false;break;}else{f