![2023年9月計算機二級考試JAVA考試題及答案_第1頁](http://file4.renrendoc.com/view/6f8584e4396834985c75347886457cdf/6f8584e4396834985c75347886457cdf1.gif)
![2023年9月計算機二級考試JAVA考試題及答案_第2頁](http://file4.renrendoc.com/view/6f8584e4396834985c75347886457cdf/6f8584e4396834985c75347886457cdf2.gif)
![2023年9月計算機二級考試JAVA考試題及答案_第3頁](http://file4.renrendoc.com/view/6f8584e4396834985c75347886457cdf/6f8584e4396834985c75347886457cdf3.gif)
![2023年9月計算機二級考試JAVA考試題及答案_第4頁](http://file4.renrendoc.com/view/6f8584e4396834985c75347886457cdf/6f8584e4396834985c75347886457cdf4.gif)
![2023年9月計算機二級考試JAVA考試題及答案_第5頁](http://file4.renrendoc.com/view/6f8584e4396834985c75347886457cdf/6f8584e4396834985c75347886457cdf5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
第頁共頁2023年9月計算機二級考試JAVA考試題及答案2023年9月計算機二級考試JAVA考試題及答案考試題一:1、編寫程序,計算以下分段函數(shù)的值。x?(x》=0)y=-x?(x<0)importjava.io.*;publicclasstesta{publicstaticvoidmain(String[]args)throwsIOException{float?x,y;InputStreamReaderreader=newInputStreamReader(System.in);BufferedReaderinput=newBufferedReader(reader);System.out.println(“請輸入x:”);Stringtemp=input.readLine;x=Float.parseFloat(temp);if(x》=0){y=x;}else{y=-x;}System.out.println(“y=”+y);}}2、根據(jù)年齡,判斷某人是否為成年。importjava.io.*;publicclasstesta{publicstaticvoidmain(String[]args)throwsIOException{intx;InputStreamReaderreader=newInputStreamReader(System.in);BufferedReaderinput=newBufferedReader(reader);System.out.println(“請輸入x:”);Stringtemp=input.readLine;x=Float.parseFloat(temp);if(x》=18){System.out.println(“成年人”);}if(x<18){System.out.println(“未成年”);}}}3、判斷2023的奇偶性,并進展輸出。publicclasstest{publicstaticvoidmain(String[]args){intx;x=2023;if(x%2==0)System.out.println(+x+“是偶數(shù)”);elseSystem.out.println(+x+“不是偶數(shù)”);}}4、比擬兩個數(shù)的大小,找出其中的最大數(shù)并輸出。importjava.io.*;publicclasska{publicstaticvoidmain(String[]args)throwsIOException{float?x,y,m;m=0;InputStreamReaderreaderx=newInputStreamReader(System.in);BufferedReaderinputx=newBufferedReader(readerx);System.out.println(“請輸入x:”);Stringtempx=inputx.readLine;x=Float.parseFloat(tempx);InputStreamReaderreadery=newInputStreamReader(System.in);BufferedReaderinputy=newBufferedReader(readery);System.out.println(“請輸入y:”);Stringtempy=inputy.readLine;y=Float.parseFloat(tempy);if(x》y){m=x;}else{m=y;}System.out.println(“最大數(shù)為”+m);}}5、比擬兩個數(shù)的大小,找出其中的最小數(shù)并輸出。importjava.io.*;publicclasska{publicstaticvoidmain(String[]args)throwsIOException{float?x,y,m;m=0;InputStreamReaderreaderx=newInputStreamReader(System.in);BufferedReaderinputx=newBufferedReader(readerx);System.out.println(“請輸入x:”);Stringtempx=inputx.readLine;x=Float.parseFloat(tempx);InputStreamReaderreadery=newInputStreamReader(System.in);BufferedReaderinputy=newBufferedReader(readery);System.out.println(“請輸入y:”);Stringtempy=inputy.readLine;y=Float.parseFloat(tempy);if(x{m=x;}else{m=y;}System.out.println(“最小數(shù)為”+m);}}6、編寫一個Java程序,判斷某年份是否為閏年。importjava.io.*;publicclasstesta{publicstaticvoidmain(String[]args)throwsIOException{float?x;InputStreamReaderreader=newInputStreamReader(System.in);BufferedReaderinput=newBufferedReader(reader);System.out.println(“請輸入x:”);Stringtemp=input.readLine;x=Float.parseFloat(temp);if(x@0==0){System.out.println(+x+“是閏年”);}elseif(x%4==0){System.out.println(+x+“是閏年”);}else{System.out.println(+x+“不是閏年”);}}}7、比擬兩個數(shù)的大小,找出其中的'最大數(shù)和最小數(shù)并輸出。importjava.io.*;publicclasska{publicstaticvoidmain(String[]args)throwsIOException{float?x,y;InputStreamReaderreaderx=newInputStreamReader(System.in);BufferedReaderinputx=newBufferedReader(readerx);System.out.println(“請輸入x:”);Stringtempx=inputx.readLine;x=Float.parseFloat(tempx);InputStreamReaderreadery=newInputStreamReader(System.in);BufferedReaderinputy=newBufferedReader(readery);System.out.println(“請輸入y:”);Stringtempy=inputy.readLine;y=Float.parseFloat(tempy);if(x{System.out.println(“最小數(shù)為”+x);System.out.println(“最大數(shù)為”+y);}else{System.out.println(“最小數(shù)為”+y);System.out.println(“最大數(shù)為”+x);}}}8、比擬兩個數(shù)的大小,找出其中的最大數(shù)和最小數(shù),并輸出最大數(shù)和最小數(shù)之差。importjava.io.*;publicclasska{publicstaticvoidmain(String[]args)throwsIOException{float?x,y,m;InputStreamReaderreaderx=newInputStreamReader(System.in);BufferedReaderinputx=newBufferedReader(readerx);System.out.println(“請輸入x:”);Stringtempx=inputx.readLine;x=Float.parseFloat(tempx);InputStreamReaderreadery=newInputStreamReader(System.in);BufferedReaderinputy=newBufferedReader(readery);System.out.println(“請輸入y:”);Stringtempy=inputy.readLine;y=Float.parseFloat(tempy);if(x{System.out.println(“最小數(shù)為”+x);System.out.println(“最大數(shù)為”+y);m=y-x;System.out.println(“最大數(shù)與最小數(shù)之差為”+m);}else{System.out.println(“最小數(shù)為”+y);System.out.println(“最大數(shù)為”+x);m=x-y;System.out.println(“最大數(shù)與最小數(shù)之差為”+m);}}}9、編寫程序,計算以下分段函數(shù)的值。x?(x》0)y=--0?(x=0)-x?(x<0)importjava.io.*;publicclasstesta{publicstaticvoidmain(String[]args)throwsIOException{float?x,y;y=0;InputStreamReaderreader=newInputStreamReader(System.in);BufferedReaderinput=newBufferedReader(reader);System.out.println(“請輸入x:”);Stringtemp=input.readLine;x=Float.parseFloat(temp);if(x》0){y=x;}if(x==0){y=0;}if(x<0){y=-x;}System.out.println(“y=”+y);}}10、編寫程序,計算以下分段函數(shù)的值。x-1?(x》1)y=--0?(-1≤x≤1)x+10?(x<-1)importjava.io.*;publicclasstesta{publicstaticvoidmain(String[]args)throwsIOException{float?x,y;y=0;InputStreamReaderreader=newInputStreamReader(System.in);BufferedReaderinput=newBufferedReader(reader);System.out.println(“請輸入x:”);Stringtemp=input.readLine;x=Float.parseFloat(temp);if(x》1){y=x-1;}if(1.0》=x--x》=-1.0){y=0;}if(x<-1){y=x+10;}System.out.println(“y=”+y);}}考試題二:1、編寫程序,實現(xiàn)1到100之間整數(shù)的累加并輸出運算結(jié)果。publicclassa{publicstaticvoidmain(String[]args){inti,s=0;for(i=1;i<=100;i++){s=s+i;}System.out.println(“1到100的累加和是”+s);}}2、編寫程序,計算1~100中奇數(shù)的累加和并輸出。publicclassa{publicstaticvoidmain(String[]args){inti,s=0;for(i=1;i<=100;i++){if(i%2!=0)s=s+i;}System.out.println(“1到100的奇數(shù)累加和是”+s);}}3、編寫程序,計算1~100中偶數(shù)的累加和并輸出。publicclassa{publicstaticvoidmain(String[]args){inti,s=0;for(i=1;i<=100;i++){if(i%2==0)s=s+i;}System.out.println(“1到100的偶數(shù)累加和是”+s);}}4、編寫程序,計算10的階乘并輸出運算結(jié)果。publicclassa{publicstaticvoidmain(String[]args){inti,s=1;for(i=1;i<=10;i++){s=s*i;}System.out.println(“10的階乘是”+s);}}5、編寫程序,計算1、2、3...的累加和,條件是和小于50。publicclassa{publicstaticvoidmain(String[]args){inti=1,s=0;label:while(true){?s=s+i;i++;if(s》50){s=s+1-i;break;}}System.out.println(“從1開場的累加和小于50的累加和是”+s);}}6、編寫程序,計算偶數(shù)2、4、6...的累加和,條件是和小于50。publicclassa{publicstaticvoidmain(String[]args){inti=1,s=0;label:while(true){?s=s+2*i;i++;if(s》50){s=s-2*i+2*1;break;}}System.out.println(“從2開場的偶數(shù)累加和小于50的累加和是”+s);}}7、編寫程序,輸出以下圖案:****************publicclassa{publicstaticvoidmain(String[]args){inti,k;for(i=1;i<=4;i++){for(k=1;k<=2*i-1;k++)System.out.print(“*”);System.out.println;}}}8、編寫程序,輸出以下圖案:****************publicclassa{publicstaticvoidmain(String[]args){inti,j,k;for(i=1;i<=4;i++){for(j=1;j<=8-2*i;j++)System.out.print(“”);for(k=1;k<=2*i-1;k++)System.out.print(“*”);System.out.println;}}}9、編寫程序,輸出以下圖案:****************publicclassa{publicstaticvoidmain(String[]args){inti,j,k;for(i=1;i<=4;i++){for(j=1;j<=2*i-2;j++)System.out.print(“”);for(k=1;k<=9-2*i;k++)System.out.print(“*”);System.out.println;}}}10、編寫程序在終端打印1~100之間的素數(shù)。publicclassa{publicstaticvoidmain(String[]args){inti,j;label:for(i=2;i<=100;i++){--?for(j=2;jif(i%j==0)continuelabel;System.out.print(+i);System.out.println;}}}11、編寫一個java程序,用窮舉法找出2~50之間的素數(shù),并打印出來。publicclasss{publicstaticvoidmain(Stringargs[]){inti,j,k;booleanflag;for(i=2;i<=50;i++){flag=true;k=i/2;for(j=2;j<=k;j++){if(i%j==0){flag=false;break;}}if(flag){System.out.println(i+“”);}}}}12、編寫一自定義方法,找出兩個數(shù)中的最大數(shù),并main方法中驗證。publicclassa{staticdoubleMax(doublex,doubley){-doublet;if(x》=y){t=x;}else{t=y;--}returnt;}publicstaticvoidmain(String[]args){doublex,y,m;x=549.265;y=56.28;m=Max(x,y);System.out.println(“最大數(shù)是”+m);System.out.println(“x=”+x+“y=”+y);if(m》=x--y<=m){System.out.println(“ture”);}else{System.out.println(“flase”);}}}13、編寫一自定義方法,找出兩個數(shù)中的最小數(shù),并main方法中驗證。publicclassa{staticdoubleMin(doublex,doubley){-doublet;if(x<=y){t=x;}else{t=y;--}returnt;}publicstaticvoidmain(String[]args){doublex,y,m;x=245.38;y=525.63;m=Mi
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024學年泰州市靖江八年級語文第一學期12月調(diào)研試卷附答案解析
- 2025年農(nóng)業(yè)物資供應鏈優(yōu)化管理協(xié)議
- 2025年專業(yè)除鼠服務合同
- 2025年出租車經(jīng)營權(quán)承接策劃協(xié)議
- 2025年通信傳輸設備項目規(guī)劃申請報告模范
- 2025年給皂液機項目提案報告模范
- 2025年農(nóng)業(yè)資源共享與協(xié)同發(fā)展協(xié)議
- 2025年建筑工程中介服務合同模板
- 2025年農(nóng)產(chǎn)品銷售合作協(xié)議合同
- 2025年棉花加工成套設備項目立項申請報告模稿
- 2025年上半年上半年重慶三峽融資擔保集團股份限公司招聘6人易考易錯模擬試題(共500題)試卷后附參考答案
- 特殊教育學校2024-2025學年度第二學期教學工作計劃
- 2025年技術(shù)員個人工作計劃例文(四篇)
- 勞保穿戴要求培訓
- 2024年物聯(lián)網(wǎng)安裝調(diào)試員(初級工)職業(yè)資格鑒定考試題庫(含答案)
- 工業(yè)控制系統(tǒng)應用與安全防護技術(shù)(微課版)課件 第1章 緒論
- 《設備科安全培訓》課件
- 藍色插畫風徽州印象旅游景點景區(qū)文化宣傳
- 2024年形勢與政策課件及講稿合集
- 無人機運營方案
- 延長石油招聘筆試題庫
評論
0/150
提交評論