java语言程序设计解答例题复习题答案06review.pdf
Chapter6Single-dimensionalArrays
1.SeethesectionDeclaringandCreatingArrays.
2.Youaccessanarrayusingitsindex.
3.Nomemoryisallocatedwhenanarrayisdeclared.Thememoryisallocatedwhen
creatingthearray.
xis60
Thesizeofnumbersis30
4.Indicatetrueorfalseforthefollowingstatements:
1.Everyelementinanarrayhasthesametype.
Answer:True
2.Thearraysizeisfixedafteritisdeclared.
Answer:False
3.Thearraysizeisfixedafteritiscreated.
Answer:True
4.Theelementinthearraymustbeofprimitivedatatype.
Answer:False
5.Whichofthefollowingstatementsarevalidarraydeclarations?
inti=newint(30);
Answer:Invalid
doubled[]=newdouble[30];
Answer:Valid
char[]r=newchar(1..30);
Answer:Invalid
inti[]=(3,4,3,2);
Answer:Invalid
floatf[]={2.3,4.5,5.6};
Answer:Valid
char[]c=newchar();
Answer:Invalid
6.Thearrayindextypeisintanditslowestindexis0.
a[2]
7.
(a)
double[]list=newdouble[10];
(b)
list[list.length–1]=5.5;
(c)
System.out.println(list[0]+list[1]