
_________________________________________________๎
Please๎write๎your๎on๎the๎top๎of๎the๎page.๎
22c:21๎Computer๎๎Science๎II:๎Data๎Structures๎
Quiz๎2B๎(open๎book๎and๎notes;๎please๎circle๎all๎the๎correct๎solutions)๎
๎
1.๎Which๎of๎the๎following๎is๎incorrect?๎
A.๎int[]๎a๎=๎new๎int[2];๎
B.๎int๎a[]๎=๎new๎int[2];๎
C.๎int[]๎a๎=๎new๎int(2);๎
D.๎int๎a๎=๎new๎int[2];๎
E.๎int๎a()๎=๎new๎int[2];๎
๎
2.๎๎How๎many๎elements๎are๎in๎array๎double[]๎list๎=๎new๎
double[5]?๎
A.๎4๎
B.๎5๎
C.๎6๎
D.๎0๎
๎
3.๎๎Analyze๎the๎following๎code.๎
public๎class๎Test๎{๎
๎๎public๎static๎void๎main(String[]๎args)๎{๎
๎๎๎๎int[]๎x๎=๎new๎int[3];๎
๎๎๎๎System.out.println("x[0]๎is๎"๎+๎x[0]);๎
๎๎}๎
}๎
A.๎The๎program๎has๎a๎compile๎error๎because๎the๎size๎of๎
the๎array๎wasn't๎specified๎when๎declaring๎the๎array.๎
B.๎The๎program๎has๎a๎runtime๎error๎because๎the๎array๎
elements๎are๎not๎initialized.๎
C.๎The๎program๎runs๎fine๎and๎displays๎x[0]๎is๎0.๎
D.๎The๎program๎has๎a๎runtime๎error๎because๎the๎array๎
element๎x[0]๎is๎not๎defined.๎
๎
4.๎How๎can๎you๎initialize๎an๎array๎of๎two๎characters๎to๎'a'๎
and๎'b'?๎
A.๎char[]๎charArray๎=๎new๎char[2];๎charArray๎=๎{'a',๎'b'};๎
B.๎char[2]๎charArray๎=๎{'a',๎'b'};๎
C.๎char[]๎charArray๎=๎{'a',๎'b'};๎
D.๎char[]๎charArray๎=๎new๎char[]{'a',๎'b'};๎
๎
5.๎๎Assume๎int[]๎scores๎=๎{1,๎20,๎30,๎40,๎50},๎what๎value๎
does๎java.util.Arrays.binarySearch(scores,๎3)๎return?๎
A.๎0๎
B.๎โ1๎
C.๎1๎
D.๎2๎
E.๎โ2๎