Professional Documents
Culture Documents
ArrayWorksheet Karel 9
ArrayWorksheet Karel 9
Karel9
Name________________________Per___
I.Answerthefollowinggiventhedeclarations:
final int max = 100;
final int size = 50;
int[ ] numbers = new int[max];
Robot[ ] robs = new Robot[size];
double[ ] values = new double[max];
1)Thevalidrangeofindexvaluesforvalues is:
1)____________________
(Note:Answershouldlooklike:110or09)
2)Thevalidrangeofindexvaluesforrobs is:
2)____________________
3)Thecomponentdatatypeofrobs is:
3)____________________
4)Thecomponentdatatypeofvalues is:
4)____________________
5)Thecomponentdatatypeoftheindexofnumbers is:
5)____________________
6)Thecomponentdatatypeoftheindexofvalues is:
6)____________________
7)Nametwoarraysthatareparallelarrays:
7)_____________________________________
II.Declareanarray,question,andinitializeitscomponentsto5,10,and70
1)Usingasinglestatement:
________________________________________________________________________
2)Usingfourstatements:
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
III.Declare
1)Writethedeclarationstatementforanarraynamedpointswhoseindexvaluesrangefrom0
through999andwhosecomponenttypeisadouble.
1)______________________________________________________________________
2)Writethedeclarationstatementfora45elementarraynamedmoverswhosecomponenttypeisthe
classBeeperMover:
2)______________________________________________________________________
3)Giventhedeclaration:char[] chars = new char[25];
writeanassignmentstatementthatstoresthevalue'R'intotheseventhlocation(component)ofthe
array:
3)______________________________________________________________________
ArrayWorksheet
Karel9
Name________________________Per___
4)______________________________________________________________________
5)Giventhemethodsignature:public void setToEleven( int [] loud)
writeanassignmentstatementthatstoresthevalue11intothelastlocation(component)ofthearray:
5)______________________________________________________________________
6)Giventhemethodsignature:public void setToOrigin(UrRobot [] homes)
writeanassignmentstatementthatstoresaCarpeterintothefirstlocation(component)ofthearray:
6)______________________________________________________________________
7)Giventhedeclaration:double[] movers = new double[10];
writeanassignmentstatementthatstoresthevalueofthethirdlocationintothesixthlocation
(component)ofthearray:
7)______________________________________________________________________
8)Giventhedeclaration:Robot[] zebra = new Robot[99];
writeanassignmentstatementthatstoreslastelementintothefirstelementofthearray:
8)______________________________________________________________________
9)Giventhemethodsignature:public void set1standLastToLast( int [] omega)
writeanassignmentstatementthatstoresthesumofvaluesofthefirstandlastelementintothelast
location(component)ofthearray:
9)______________________________________________________________________
10)Giventhemethodsignature:public void setToOrigin(Sorter [] sorts)
writecommandtomakethelastelementofthearraypickupabeeper:
10)______________________________________________________________________
11)Giventhemethodsignature:public void setAllToA( char [] grades)
writecodetoassignthevaluereturnedbysomeRandomLetter()intoeachlocationofthearray.
Usingtwolines:
________________________________________________________________________
________________________________________________________________________
12)Giventhemethodsignature:public void goToOrigin(Sorter [] sorts)
writecodetocommandallrobotsinthearraytogoToOrigin.Usingtwolines:
________________________________________________________________________
________________________________________________________________________