
_________________________________________________
Pleasewriteyouronthetopofthepage.
22c:21ComputerScienceII:DataStructures
Quiz2B(openbookandnotes;pleasecircleallthecorrectsolutions)
1.Whichofthefollowingisincorrect?
A.int[]a=newint[2];
B.inta[]=newint[2];
C.int[]a=newint(2);
D.inta=newint[2];
E.inta()=newint[2];
2.Howmanyelementsareinarraydouble[]list=new
double[5]?
A.4
B.5
C.6
D.0
3.Analyzethefollowingcode.
publicclassTest{
publicstaticvoidmain(String[]args){
int[]x=newint[3];
System.out.println("x[0]is"+x[0]);
}
}
A.Theprogramhasacompileerrorbecausethesizeof
thearraywasn'tspecifiedwhendeclaringthearray.
B.Theprogramhasaruntimeerrorbecausethearray
elementsarenotinitialized.
C.Theprogramrunsfineanddisplaysx[0]is0.
D.Theprogramhasaruntimeerrorbecausethearray
elementx[0]isnotdefined.
4.Howcanyouinitializeanarrayoftwocharactersto'a'
and'b'?
A.char[]charArray=newchar[2];charArray={'a','b'};
B.char[2]charArray={'a','b'};
C.char[]charArray={'a','b'};
D.char[]charArray=newchar[]{'a','b'};
5.Assumeint[]scores={1,20,30,40,50},whatvalue
doesjava.util.Arrays.binarySearch(scores,3)return?
A.0
B.‐1
C.1
D.2
E.‐2