
Pleasewriteryouronthetopofthepage.
22c:21ComputerScienceII:DataStructures
Quiz2A(openbookandnotes;pleasecircleallthecorrectsolutions)
1.Ifyoudeclareanarraydouble[]list={3.4,2.0,3.5,
5.5},list[1]is________.
A.3.4
B.2.0
C.3.4
D.5.5
E.undefined
2.Ifyoudeclareanarraydouble[]list={3.4,2.0,3.5,
5.5},thehighestindexinarraylistis__________.
A.0
B.1
C.2
D.3
E.4
3.Supposeinti=5,whichofthefollowingcanbeused
asanindexforarraydouble[]t=newdouble[100]?
A.i
B.(int)(Math.random()*100))
C.i+10
D.i+6.5
E.Math.random()*100
4.Whichofthefollowingstatementsisvalid?
A.inti=newint(30);
B.doubled[]=newdouble[30];
C.int[]i={3,4,3,2};
D.char[]c=newchar();
E.char[]c=newchar[4]{'a','b','c','d'};
5.Whatwouldbetheresultofattemptingtocompile
andrunthefollowingcode?
publicclassTest{
publicstaticvoidmain(String[]args){
double[]x=newdouble[]{1,2,3};
System.out.println("Valueis"+x[1]);
}
}
A.Theprogramhasacompileerrorbecausethesyntax
newdouble[]{1,2,3}iswronganditshouldbereplaced
by{1,2,3}.
B.Theprogramhasacompileerrorbecausethesyntax
newdouble[]{1,2,3}iswronganditshouldbereplaced
bynewdouble[3]{1,2,3};
C.Theprogramhasacompileerrorbecausethesyntax
newdouble[]{1,2,3}iswronganditshouldbereplaced
bynewdouble[]{1.0,2.0,3.0};
D.Theprogramcompilesandrunsfineandtheoutput
"Valueis1.0"isprinted.
E.Theprogramcompilesandrunsfineandtheoutput
"Valueis2.0"isprinted.
6.Assumeint[]t={1,2,3,4}.Whatist.length?
A.0
B.3
C.4
D.5