Java數(shù)據(jù)類型的轉(zhuǎn)化專項(xiàng)測(cè)試題附答案_第1頁(yè)
Java數(shù)據(jù)類型的轉(zhuǎn)化專項(xiàng)測(cè)試題附答案_第2頁(yè)
Java數(shù)據(jù)類型的轉(zhuǎn)化專項(xiàng)測(cè)試題附答案_第3頁(yè)
Java數(shù)據(jù)類型的轉(zhuǎn)化專項(xiàng)測(cè)試題附答案_第4頁(yè)
Java數(shù)據(jù)類型的轉(zhuǎn)化專項(xiàng)測(cè)試題附答案_第5頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

Java數(shù)據(jù)類型的轉(zhuǎn)化專項(xiàng)測(cè)試題附答案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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論