wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Introduction to Arrays

Total questions: 10

Worksheet time: 6mins

Name
Class
Date
1.
What are the legal indexes for the array ar, given the following declaration:
int[] ar = {2, 4, 6, 8 }
a)
 0, 1, 2, 3
b)
 1, 2, 3, 4
c)
2, 4, 6, 8
d)
 0, 2, 4, 6
2.
Which of the following declares an array of int named img?
a)
int img;
b)
int[] img;
c)
new int img[];
d)
int img = int[];
3.
What is the output of the following code fragment:
int[] ar = {2, 4, 6, 8 };
 System.out.println( ar[0] + " " + ar[1] ); 
a)
 2 6
b)
8
c)
 2 4
d)
 6 8
4.
What is the output of the following code fragment:
int[] ar = {2, 4, 6, 8 }; ar[0] = 23; ar[3] = ar[1]; SOP( ar[0] + " " + ar[3] );
a)
23 2
b)
2 8
c)
31
d)
23 4
5.
What is the output of the following code fragment:
int[] y = new int[5]; y[0] = 34; y[1] = 88; SOP( y[0] + " " + y[1] + " " + y[5] );
a)
34 88 0
b)
34 88 88
c)
 The program is defective and will not compile.
d)
0 34 88
6.
What is the output of the following code fragment:
int[] z = new int[9]; 
z[0] = 7;
z[1] = 3; 
z[2] = 4; 
SOP(z[0] + z[1] + " " + z[5] ); 
a)
10 0
b)
7 3 0
c)
The program is defective and will not compile.
d)
7 3 4
7.
What expression represents the last element of any size array named array?

a)
array[length-1]
b)
array[length]
c)
 array[array.length]
d)
array[array.length-1]
8.
What is the output of the following code fragment:
int[] zip = new int[5]; 
zip[0] = 7; 
zip[1] = 3; 
zip[2] = 4; 
zip[3] = 1; 
zip[4] = 9; 
int j = 3; 
System.out.println( zip[ j-1 ] );

a)
7
b)
3
c)
4
d)
1
9.
 How many objects are present after the following code fragment has executed?
double[] ann = new double[ 7 ]; double[] bob; bob = ann; 
a)
2
b)
7
c)
14
d)
1
10.
For which of the following applications is an array NOT suitable:
a)
Holding the scores on twelve midterms exams of a class
b)
Holding the name, social security number, age, and income of one individual.
c)
Holding the temperature readings taken every hour throughout a day.
d)
Holding the total sales a store made in each of twelve months.