




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
本文格式為Word版,下載可任意編輯——2022年9月計算機(jī)二級考試JAVA考試題及答案2022年下半年計算機(jī)二級考試正在備考中。你知道計算機(jī)二級考試JAVA科目都考哪些學(xué)識嗎?為了便當(dāng)考生備考計算機(jī)二級考試JAVA科目。下面是我為大家?guī)淼挠嬎銠C(jī)二級考試JAVA考試題,接待閱讀。
考試題一:
1、編寫程序,計算以下分段函數(shù)的值。
x?x=0
y=
-x?x0
importjava.io.*;
publicclasstesta
publicstaticvoidmainString[]argsthrowsIOException
float?x,y;
InputStreamReaderreader=newInputStreamReaderSystem.in;
BufferedReaderinput=newBufferedReaderreader;
System.out.println請輸入x:;
Stringtemp=input.readLine;
x=Float.parseFloattemp;
ifx=0
y=x;
else
y=-x;
System.out.printlny=+y;
2、根據(jù)年齡,判斷某人是否為成年。
importjava.io.*;
publicclasstesta
publicstaticvoidmainString[]argsthrowsIOException
intx;
InputStreamReaderreader=newInputStreamReaderSystem.in;
BufferedReaderinput=newBufferedReaderreader;
System.out.println請輸入x:;
Stringtemp=input.readLine;
x=Float.parseFloattemp;
ifx=18
System.out.println成年人;
ifx18
System.out.println未成年;
3、判斷2022的奇偶性,并舉行輸出。
publicclasstest
publicstaticvoidmainString[]args
intx;
x=2022;
ifx%2==0
System.out.println+x+是偶數(shù);
else
System.out.println+x+不是偶數(shù);
4、對比兩個數(shù)的大小,找出其中的最大數(shù)并輸出。
importjava.io.*;
publicclasska
publicstaticvoidmainString[]argsthrowsIOException
float?x,y,m;
m=0;
InputStreamReaderreaderx=newInputStreamReaderSystem.in;
BufferedReaderinputx=newBufferedReaderreaderx;
System.out.println請輸入x:;
Stringtempx=inputx.readLine;
x=Float.parseFloattempx;
InputStreamReaderreadery=newInputStreamReaderSystem.in;
BufferedReaderinputy=newBufferedReaderreadery;
System.out.println請輸入y:;
Stringtempy=inputy.readLine;
y=Float.parseFloattempy;
ifxy
m=x;
else
m=y;
System.out.println最大數(shù)為+m;
5、對比兩個數(shù)的大小,找出其中的最小數(shù)并輸出。
importjava.io.*;
publicclasska
publicstaticvoidmainString[]argsthrowsIOException
float?x,y,m;
m=0;
InputStreamReaderreaderx=newInputStreamReaderSystem.in;
BufferedReaderinputx=newBufferedReaderreaderx;
System.out.println請輸入x:;
Stringtempx=inputx.readLine;
x=Float.parseFloattempx;
InputStreamReaderreadery=newInputStreamReaderSystem.in;
BufferedReaderinputy=newBufferedReaderreadery;
System.out.println請輸入y:;
Stringtempy=inputy.readLine;
y=Float.parseFloattempy;
ifx
m=x;
else
m=y;
System.out.println最小數(shù)為+m;
6、編寫一個Java程序,判斷某年份是否為閏年。
importjava.io.*;
publicclasstesta
publicstaticvoidmainString[]argsthrowsIOException
float?x;
InputStreamReaderreader=newInputStreamReaderSystem.in;
BufferedReaderinput=newBufferedReaderreader;
System.out.println請輸入x:;
Stringtemp=input.readLine;
x=Float.parseFloattemp;
ifx@0==0
System.out.println+x+是閏年;
else
ifx%4==0
System.out.println+x+是閏年;
elseSystem.out.println+x+不是閏年;
7、對比兩個數(shù)的大小,找出其中的最大數(shù)和最小數(shù)并輸出。
importjava.io.*;
publicclasska
publicstaticvoidmainString[]argsthrowsIOException
float?x,y;
InputStreamReaderreaderx=newInputStreamReaderSystem.in;
BufferedReaderinputx=newBufferedReaderreaderx;
System.out.println請輸入x:;
Stringtempx=inputx.readLine;
x=Float.parseFloattempx;
InputStreamReaderreadery=newInputStreamReaderSystem.in;
BufferedReaderinputy=newBufferedReaderreadery;
System.out.println請輸入y:;
Stringtempy=inputy.readLine;
y=Float.parseFloattempy;
ifx
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
publicstaticvoidmainString[]argsthrowsIOException
float?x,y,m;
InputStreamReaderreaderx=newInputStreamReaderSystem.in;
BufferedReaderinputx=newBufferedReaderreaderx;
System.out.println請輸入x:;
Stringtempx=inputx.readLine;
x=Float.parseFloattempx;
InputStreamReaderreadery=newInputStreamReaderSystem.in;
BufferedReaderinputy=newBufferedReaderreadery;
System.out.println請輸入y:;
Stringtempy=inputy.readLine;
y=Float.parseFloattempy;
ifx
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?x0
y=????0?x=0
-x?x0
importjava.io.*;
publicclasstesta
publicstaticvoidmainString[]argsthrowsIOException
float?x,y;
y=0;
InputStreamReaderreader=newInputStreamReaderSystem.in;
BufferedReaderinput=newBufferedReaderreader;
System.out.println請輸入x:;
Stringtemp=input.readLine;
x=Float.parseFloattemp;
ifx0
y=x;
ifx==0
y=0;
ifx0
y=-x;
System.out.printlny=+y;
10、編寫程序,計算以下分段函數(shù)的值。
x-1?x1
y=????0?-1≤x≤1
x+10?x-1
importjava.io.*;
publicclasstesta
publicstaticvoidmainString[]argsthrowsIOException
float?x,y;
y=0;
InputStreamReaderreader=newInputStreamReaderSystem.in;
BufferedReaderinput=newBufferedReaderreader;
System.out.println請輸入x:;
Stringtemp=input.readLine;
x=Float.parseFloattemp;
ifx1
y=x-1;
if1.0=xx=-1.0
y=0;
ifx-1
y=x+10;
System.out.printlny=+y;
考試題二:
1、編寫程序,實現(xiàn)1到100之間整數(shù)的累加并輸出運(yùn)算結(jié)果。
publicclassa
publicstaticvoidmainString[]args
inti,s=0;
fori=1;i=100;i++
s=s+i;
System.out.println1到100的累加和是+s;
2、編寫程序,計算1~100中奇數(shù)的累加和并輸出。
publicclassa
publicstaticvoidmainString[]args
inti,s=0;
fori=1;i=100;i++
ifi%2!=0
s=s+i;
System.out.println1到100的奇數(shù)累加和是+s;
3、編寫程序,計算1~100中偶數(shù)的累加和并輸出。
publicclassa
publicstaticvoidmainString[]args
inti,s=0;
fori=1;i=100;i++
ifi%2==0
s=s+i;
System.out.println1到100的偶數(shù)累加和是+s;
4、編寫程序,計算10的階乘并輸出運(yùn)算結(jié)果。
publicclassa
publicstaticvoidmainString[]args
inti,s=1;
fori=1;i=10;i++
s=s*i;
System.out.println10的階乘是+s;
5、編寫程序,計算1、2、3...的累加和,條件是和小于50。
publicclassa
publicstaticvoidmainString[]args
inti=1,s=0;
label:
whiletrue
?s=s+i;
i++;
ifs50
s=s+1-i;
break;
System.out.println從1開頭的累加和小于50的累加和是+s;
6、編寫程序,計算偶數(shù)2、4、6...的累加和,條件是和小于50。
publicclassa
publicstaticvoidmainString[]args
inti=1,s=0;
label:
whiletrue
?s=s+2*i;
i++;
ifs50
s=s-2*i+2*1;
break;
System.out.println從2開頭的偶數(shù)累加和小于50的累加和是+s;
7、編寫程序,輸出以下圖案:
*
***
*****
*******
publicclassa
????????publicstaticvoidmainString[]args
inti,k;
fori=1;i=4;i++
fork=1;k=2*i-1;k++
System.out.print*;
System.out.println;
8、編寫程序,輸出以下圖案:
*
***
*****
*******
publicclassa
????????publicstaticvoidmainString[]args
inti,j,k;
fori=1;i=4;i++
forj=1;j=8-2*i;j++
System.out.print;
fork=1;k=2*i-1;k++
System.out.print*;
System.out.println;
9、編寫程序,輸出以下圖案:
*******
*****
***
*
publicclassa
????????publicstaticvoidmainString[]args
inti,j,k;
fori=1;i=4;i++
forj=1;j=2*i-2;j++
System.out.print;
fork=1;k=9-2*i;k++
System.out.print*;
System.out.println;
10、編寫程序在終端打印1~100之間的素數(shù)。
publicclassa
????????publicstaticvoidmainString[]args
inti,j;
label:
fori=2;i=100;i++
?????forj=2;jifi%j==0
continuelabel;
System.out.print+i;
System.out.println;
11、編寫一個java程序,用窮舉法找出2~50之間的素數(shù),并打印出來。
publicclasss
publicstaticvoidmainStringargs[]
inti,j,k;
booleanflag;
fori=2;i=50;i++
flag=true;
k=i/2;
forj=2;j=k;j++
ifi%j==0
flag=false;
break;
ifflag
System.out.printlni+;
12、編寫一自定義方法,找出兩個數(shù)中的最大數(shù),并main方法中驗證。
publicclassa
staticdoubleMaxdoublex,doubley
??doublet;
ifx=y
t=x;
else
t=y;????
returnt;
publicstaticvoidmainString[]args
doublex,y,m;
x=549.265;
y=56.28;
m=Maxx,y;
System.out.println最大數(shù)是+m;
System.out.printlnx=+x+y=+y;
ifm=xy=m
System.out.printlnture;
else
System.out.printlnflase;
13、編寫一自定義方法,找出兩個數(shù)中的最小數(shù),并main方法中驗證。
publicclassa
staticdoubleMindoublex,doubley
??doublet;
ifx=y
t=x;
else
t=y;????
returnt;
publicstaticvoidmainString[]
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 個性化健康監(jiān)測解決方案策略考核試卷
- 藥品認(rèn)證與藥品生產(chǎn)設(shè)備管理要求考核試卷
- 體育會展創(chuàng)意思維訓(xùn)練對賽事市場推廣的影響考核試卷
- 化工生產(chǎn)中化學(xué)品事故預(yù)警系統(tǒng)研究考核試卷
- 護(hù)理蒙語面試題及答案
- java遞歸面試題及答案
- 消防月考試試題及答案
- 章魚介紹課件
- 技術(shù)合作開發(fā)合同模板
- 學(xué)習(xí)習(xí)慣與自主能力培養(yǎng)
- 游泳教練員聘用協(xié)議(適用版)5篇
- 北京市海淀區(qū)2023-2024學(xué)年高一下學(xué)期7月期末考試數(shù)學(xué)試題(解析版)
- 2024年貴州省普通高校招生信息表(普通類本科批-歷史組合)
- 2024年遼寧省中考地理試卷(含答案)
- DB13-T5715-2023養(yǎng)老機(jī)構(gòu)特殊困難老年人社會工作服務(wù)規(guī)范
- 【課件】臺灣的社區(qū)總體營造
- 胸痛課件教學(xué)課件
- 《0~6歲兒童行為測聽操作規(guī)范》
- 廟會策劃方案
- 2024-2030年中國液壓機(jī)行業(yè)市場發(fā)展趨勢與前景展望戰(zhàn)略分析報告
- 2023年黑龍江農(nóng)業(yè)經(jīng)濟(jì)職業(yè)學(xué)院招聘考試真題
評論
0/150
提交評論