




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
Java數(shù)據(jù)類型的轉(zhuǎn)化專項測試題附答案1.Inthecodesegmentbelow,assumethattheintvariablesaandbhavebeenproperlydeclaredandinitialized.
intc=a;
intd=b;
c+=3;
d--;
doublenum=c;
num/=d;
Whichofthefollowingbestdescribesthebehaviorofthecodesegment?Thecodesegmentstoresthevalueof(a+3)/binthevariablenum.Thecodesegmentstoresthevalueof(a+3)/(b-1)inthevariablenum.(正確答案)Thecodesegmentstoresthevalueof(a+3)/(b-2)inthevariablenum.Thecodesegmentstoresthevalueof(a+3)/(1-b)inthevariablenum.Thecodesegmentcausesaruntimeerrorinthelastlineofcodebecausenumistypedoubleanddistypeint.2.Considerthefollowingcodesegment,whichisintendedtofindtheaverageoftwopositiveintegers,xandy.
intx;
inty;
intsum=x+y;
doubleaverage=(double)(sum/2);
Whichofthefollowingbestdescribestheerror,ifany,inthecodesegment?Thereisnoerror,andthecodeworksasintended.Intheexpression(double)(sum/2),thecasttodoubleisappliedtoolate,sotheaveragewillbelessthantheexpectedresultforevenvaluesofsum.Intheexpression(double)(sum/2),thecasttodoubleisappliedtoolate,sotheaveragewillbegreaterthantheexpectedresultforevenvaluesofsum.Intheexpression(double)(sum/2),thecasttodoubleisappliedtoolate,sotheaveragewillbelessthantheexpectedresultforoddvaluesofsum.(正確答案)Intheexpression(double)(sum/2),thecasttodoubleisappliedtoolate,sotheaveragewillbegreaterthantheexpectedresultforoddvaluesofsum.3.Considerthefollowingcodesegment.
doublenum=9/4;
System.out.print(num);
System.out.print("");
System.out.print((int)num);
Whatisprintedasaresultofexecutingthecodesegment?222.02(正確答案)2.02.02.2522.252.04.Considerthefollowingcodesegment.
doublex=(int)(5.5-2.5);
doubley=(int)5.5-2.5;
System.out.println(x-y);
Whatisprintedasaresultofexecutingthecodesegment?-1.0-0.50.00.5(正確答案)1.05.Considerthefollowingcodesegment.
intw=1;
intx=w/2;
doubley=3;
intz=(int)(x+y);
Whichofthefollowingbestdescribestheresultsofcompilingthecodesegment?Thecodesegmentcompileswithouterror.(正確答案)Thecodesegmentdoesnotcompile,becausetheintvariablexcannotbeassignedtheresultoftheoperationw/2.Thecodesegmentdoesnotcompile,becausetheintegervalue3cannotbeassignedtothedoublevariabley.Thecodesegmentdoesnotcompile,becausetheoperandsoftheadditionoperatorcannotbeofdifferenttypesintanddouble.Thecodesegmentdoesnotcompilebecausetheresultoftheadditionoperationisoftypedoubleandcannotbecasttoanint.6.Considerthefollowingcodesegment.
doublex=4.5;
inty=(int)x2;
System.out.print(y);
Whatisprintedasaresultofexecutingthecodesegment?8(正確答案)8.099.0107.Considerthefollowingcodesegment.
inta=5;
intb=4;
intc=2;
a=3;
b+=a;
b/=c;
System.out.print(b);
Whatisprintedwhenthecodesegmentisexecuted?249(正確答案)9.5198.Considerthefollowingcodesegment.
num+=num;
num=num;
Assumethatnumhasbeenpreviouslydeclaredandinitializedtocontainanintegervalue.Whichofthefollowingbestdescribesthebehaviorofthecodesegment?Thevalueofnumistwotimesitsoriginalvalue.Thevalueofnumisthesquareitsoriginalvalue.Thevalueofnumistwotimesthesquareofitsoriginalvalue.Thevalueofnumisthesquareoftwiceitsoriginalvalue.(正確答案)Itcannotbedeterminedwithoutknowingtheinitialvalueofnum.9.Considerthefollowingcodesegment.
intx=5;
x+=62;
x-=3/2;
Whatvalueisstoredinxafterthecodesegmentexecutes?-1.51915.516(正確答案)10.Considerthefollowingcodesegment,wherekandcountareproperlydeclaredandinitializedintvariables.
k++;
k++;
count++;
k--;
count++;
k--;
Whichofthefollowingbestdescribesthebehaviorofthecodesegment?Thecodesegmentleavesbothkandcountunchanged.Thecodesegmentincreasesbothkandcountby2.Thecodesegmentincreaseskby4andcountby2.Thecodesegmentleaveskunchangedandincreasescountby2.(正確答案)Thecodesegmentincreaseskby2andleavescountunchanged.11.Considerthefollowingcodesegment.
inta=4;
intb=5;
a++;
b++;
intc=a+b;
a-=1;
System.out.println(a+c);
Whatisprintedwhenthecodesegmentisexecuted?9101415(正確答案)2512.Thefollowingcodesegmentisintendedtoroundvaltothenearestintegerandprinttheresult.
doubleval=-0.7;
introundedVal=(int)(val+0.5);
System.out.println(roundedVal);
Whichofthefollowingbestdescribesthebehaviorofthecodesegment?Thecodesegmentworksasintended.ThecodesegmentdoesnotworkasintendedbecausevalandroundedValshouldbedeclaredasthesamedatatype.Thecodesegmentdoesnotworkasintendedbecausetheexpression(val+0.5)shouldbecasttoadoubleinsteadofanint.Thecodesegmentdoesnotworkasintendedbecausevalshouldbecasttoanintbefore0.5isaddedtoit.Thecodesegmentdoesnotworkasintendedbecausetheexpression(int)(val+0.5)roundstothenearestintegeronlywhenvalispositive.(正確答案)13.Considerthefollowingcodesegment.
System.out.print(Idonotfearcomputers.);//Line1
System.out.println(Ifearthelackofthem.);//Line2
System.out.println(--IsaacAsimov);//Line3
Thecodesegmentisintendedtoproducethefollowingoutputbutmaynotworkasintended.
Idonotfearcomputers.Ifearthelackofthem.
--IsaacAsimov
Whichchange,ifany,canbemadesothatthecodesegmentproducestheintendedoutput?Inline1,printshouldbechangedtoprintln.Inlines2and3,printlnshouldbechangedtoprint.ThestatementSystem.out.println()shouldbeinsertedbetweenlines2and3.Inlines1,2,and3,thetextthatappearsinparenthesesshouldbeenclosedinquotationmarks.(正確答案)Nochangeisneeded;thecodesegmentworkscorrectlyasis.14.Considerthefollowingcodesegment.
System.out.print();//Line1
System.out.print("");//Line2
System.out.println();//Line3
System.out.println("");//Line4
Thecodesegmentisintendedtoproducethefollowingoutput,butmaynotworkasintended.
Whichlineofcode,ifany,causesanerror?Line1(正確答案)Line2Line3Line4Thecodesegmentworksasintended.15.Considerthefollowingcodesegment.
System.out.print("One");//Line1
System.out.print("Two");//Line2
System.out.print("Three");//Line3
System.out.print("Four");//Line4
Thecodesegmentisintendedtoproducethefollowingoutput,butdoesnotworkasintended.
OneTwo
ThreeFour
Whichofthefollowingchangescanbemadesothatthecodesegmentproducestheintendedoutput?Changingprinttoprintlninline1onlyChangingprinttoprintlninline2only(正確答案)Changingprinttoprintlninline3onlyChangingprinttoprintlninlines2and3onlyChangingprinttoprintlninlines1,2,3,and416.Considerthefollowingcodesegment.
Whatisprintedasaresultofexecutingthecodesegment?
0124(正
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年個人與企業(yè)融資合同范文示范文本
- 2025年二手房交易合同指導(dǎo)文本
- 暑期臨時工勞動合同模板
- 2025年國際貿(mào)易電商合作合同
- 2025年公共機構(gòu)設(shè)備采購合同履行
- 2025年樺木供應(yīng)合同格式
- 2025年信譽質(zhì)押合同樣本
- 2025年農(nóng)業(yè)繁殖項目合同
- 建筑工程2025年勞務(wù)協(xié)作合同樣本
- 2025年信報箱訂購合同示范文本
- 河南省鄭州市外國語學(xué)校2025屆高考壓軸卷英語試卷含解析
- 2024年教育創(chuàng)新:五年級下冊美術(shù)教案新解讀
- 2024年燃氣輪機值班員技能鑒定理論知識考試題庫-下(多選、判斷題)
- 交通法規(guī)課件
- (優(yōu)化版)高中地理新課程標準【2024年修訂版】
- 儲能電池模組PACK和系統(tǒng)集成項目可行性研究報告
- 《Python程序設(shè)計》課件-1:Python簡介與應(yīng)用領(lǐng)域
- 各類心理量表大全
- DB12T990-2020建筑類建設(shè)工程規(guī)劃許可證設(shè)計方案規(guī)范
- 2023-2024學(xué)年九年級三調(diào)語文試卷(含答案)
- 交通運輸概論課件:綜合交通運輸體系
評論
0/150
提交評論