您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 《Java语言程序设计:基础篇》课后复习题答案-第六章
Chapter6Single-dimensionalArrays1.SeethesectionDeclaringandCreatingArrays.2.Youaccessanarrayusingitsindex.3.Nomemoryisallocatedwhenanarrayisdeclared.Thememoryisallocatedwhencreatingthearray.xis60Thesizeofnumbersis304.Indicatetrueorfalseforthefollowingstatements:1.Everyelementinanarrayhasthesametype.Answer:True2.Thearraysizeisfixedafteritisdeclared.Answer:False3.Thearraysizeisfixedafteritiscreated.Answer:True4.Theelementinthearraymustbeofprimitivedatatype.Answer:False5.Whichofthefollowingstatementsarevalidarraydeclarations?inti=newint(30);Answer:Invaliddoubled[]=newdouble[30];Answer:Validchar[]r=newchar(1..30);Answer:Invalidinti[]=(3,4,3,2);Answer:Invalidfloatf[]={2.3,4.5,5.6};Answer:Validchar[]c=newchar();Answer:Invalid6.Thearrayindextypeisintanditslowestindexis0.a[2]7.(a)double[]list=newdouble[10];(b)list[list.length–1]=5.5;(c)System.out.println(list[0]+list[1]);(d)doublesum=0;for(inti=0;ilist.length;i++)sum+=list[i];(e)doublemin=list[0];for(inti=1;ilist.length;i++)if(minlist[i])min=list[i];(f)System.out.println(list[(int)(Math.random()*list.length));(g)double[]={3.5,5.5,4.52,5.6};8.Aruntimeexceptionoccurs.9.Line3:thearraydeclarationiswrong.Itshouldbedouble[].Thearrayneedstobecreatedbeforeitsbeenused.e.g.newdouble[10]Line5:Thesemicolon(;)attheendoftheforloopheadingshouldberemoved.Line5:r.length()shouldber.length.Line6:randomshouldberandom()Line6:r(i)shouldber[i].10.System.arraycopy(source,0,t,0,source.length);11.ThesecondassignmentstatementmyList=newint[20]createsanewarrayandassignsitsreferencetomyList.myListnewint[10]ArraymyListnewint[10]Arraynewint[20]Array12.False.Whenanarrayispassedtoamethod,thereferencevalueofthearrayispassed.Nonewarrayiscreated.Bothargumentandparameterpointtothesamearray.13.numbersis0andnumbers[0]is314.(A)ExecutingcreateArrayinLine6Spacerequiredforthemainmethodchar[]chars:refHeapArrayof100charactersSpacerequiredforthecreateArraymethodchar[]chars:ref(B)AfterexitingcreateArrayinLine6Spacerequiredforthemainmethodchar[]chars:refHeapArrayof100charactersStackStack(C)ExecutingdisplayArrayinLine10Spacerequiredforthemainmethodchar[]chars:refHeapArrayof100charactersSpacerequiredforthedisplayArraymethodchar[]chars:ref(D)AfterexitingdisplayArrayinLine10Spacerequiredforthemainmethodchar[]chars:refHeapArrayof100charactersStackStack(E)ExecutingcountLettersinLine13Spacerequiredforthemainmethodint[]counts:refchar[]chars:refHeapArrayof100charactersSpacerequiredforthecountLettersmethodint[]counts:refchar[]chars:ref(F)AfterexitingcountLettersinLine13Spacerequiredforthemainmethodint[]counts:refchar[]chars:refHeapArrayof100charactersStackStackArrayof26integersArrayof26integers(G)ExecutingdisplayCountsinLine18Spacerequiredforthemainmethodint[]counts:refchar[]chars:refHeapArrayof100charactersSpacerequiredforthedisplayCountsmethodint[]counts:ref(H)AfterexitingdisplayCountsinLine18Spacerequiredforthemainmethodint[]counts:refchar[]chars:refHeapArrayof100charactersStackStackArrayof26integersArrayof26integers15.Onlyonevariable-lengthparametermaybespecifiedinamethodandthisparametermustbethelastparameter.Themethodreturntypecannotbeavariable-lengthparameter.16.ThelastoneprintMax(newint[]{1,2,3});isincorrect,becausethearraymustofthedouble[]type.17.Omitted18.Omitted19.Omitted20Simplychange(currentMaxlist[j])onLine10to(currentMaxlist[j])21Simplychangelist[k]currentElementonLine9tolist[k]currentElement22.Youcansortanarrayofanyprimitivetypesexceptboolean.Thesortmethodisvoid,soitdoesnotreturnanewarray.23.Toapplyjava.util.Arrays.binarySearch(array,key),thearraymustbesortedinincreasingorder.24.Line1:listis{2,4,7,10}Line2:listis{7,7,7,7}Line3:listis{7,8,8,7}Line4:listis{7,8,8,7}
本文标题:《Java语言程序设计:基础篇》课后复习题答案-第六章
链接地址:https://www.777doc.com/doc-4270732 .html