NEW
Font size
WorksheetsJava Quiz 3 - Array
Total questions: 11
Worksheet time: 6mins
Array is
immutable
mutable
always contant
Which of the following declares an array of int named img?
int img;
int[] img;
new int img[];
int img = int[];
What are the legal indexes for the array ar, given the following declaration:
int[] ar = {2, 4, 6, 8 };
0, 1, 2, 3
1, 2, 3, 4
2, 4, 6, 8
0, 2, 4. 6
What is the output of the following code fragment:
int[] ar = {2, 4, 6, 8 };
System.out.println( ar[0] + " " + ar[1] );
2 6
8
2 4
6 8
What is the output of the following code fragment:
int[] ar = {2, 4, 6, 8 };
ar[0] = 23;
ar[3] = ar[1];
System.out.println( ar[0] + " " + ar[3] );
23 2
2 8
31
23 4
What is the output of the following code fragment:
int[] y = new int[5];
y[0] = 34;
y[1] = 88;
System.out.println( y[0] + " " + y[1] + " " + y[5] );
34 88 0
34 88 88
The program is defective and will not compile
0 34 88
What is the output of the following code fragment:
int[] z = new int[9];
z[0] = 7;
z[1] = 3;
z[2] = 4;
System.out.println( z[0] + z[1] + " " + z[5] );
10 0
7 3 0
The program is defective and will not compile.
7 3 4
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;
System.out.println( zip[ 2 + 1 ] );
4 3
3
4
1
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 ] );
7
3
4
1
How many objects are present after the following code fragment has executed?
double[] ann = new double[ 7 ];
double[] bob;
bob = ann;
2
7
14
1
For which of the following applications is an array NOT suitable:
Holding the scores on twelve midterms exams of a class.
Holding the name, social security number, age, and income of an individual.
Holding the temperature readings taken every hour throughout a day.
Holding the total sales a store made in each of twelve months.
