wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Quiz 3 - Array

Total questions: 11

Worksheet time: 6mins

Name
Class
Date
1.

Array is

a)

immutable

b)

mutable

c)

always contant

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 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

4.

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

5.

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] );

a)

23 2

b)

2 8

c)

31

d)

23 4

6.

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] );

a)

34 88 0

b)

34 88 88

c)

The program is defective and will not compile

d)

0 34 88

7.

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] );

a)

10 0

b)

7 3 0

c)

The program is defective and will not compile.

d)

7 3 4

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;

System.out.println( zip[ 2 + 1 ] );

a)

4 3

b)

3

c)

4

d)

1

9.

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

10.

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

11.

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 an 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.