Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Array - II

Total questions: 10

Worksheet time: 2mins

Name
Class
Date
1.

Which of the following correctly prints all elements of an array arr?

a)

for(int i=0; i<=arr.length; i++)

b)

for(int i=0; i<arr.length; i++)

c)

for(int i=1; i<arr.length; i++)

d)

for(int i=0; i>arr.length; i++)

2.

int[] a = {5, 10, 15};

System.out.print(a[0]);

a)

0

b)

5

c)

10

d)

Error

3.

int[] a = {2, 4, 6, 8};

System.out.print(a.length);

a)

3

b)

4

c)

5

d)

Error

4.

int[] a = {1, 3, 5};

System.out.print(a[1] + a[2]);

a)

4

b)

6

c)

8

d)

Error

5.

int[] a = {1, 2, 3};

System.out.print(a[3]);

a)

0

b)

3

c)

Compilation Error

d)

Runtime Error

6.

int[] a = {4, 6, 8};

a[1] = 10;

System.out.print(a[1]);

a)

6

b)

8

c)

10

d)

Error

7.

Which of the following correctly declares a 2D array in Java?

a)

int a = new int[2][3];

b)

int[][] a = new int[2][3];

c)

int[2][3] a;

d)

array a[2][3];

8.

int[][] a = {{1, 2}, {3, 4}};

System.out.print(a[0][1]);

a)

1

b)

2

c)

3

d)

4

9.

How many rows are there in the following 2D array?

int[][] a = new int[3][2];

a)

2

b)

3

c)

5

d)

6

10.

int[][] a = new int[2][2];

System.out.print(a[1][1]);

a)

1

b)

null

c)

0

d)

error