Search Header Logo

2D Arrays in Java Quiz

Authored by Mister Swagner

Computers

12th Grade

20 Questions

Used 3+ times

2D Arrays in Java Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How do you declare a 2D array in Java?

`int[][] array2D;`

`int array2D[][];`

`int[2][2] array2D;`

Both A and B are correct.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is the correct way to initialize a 2D array in Java?

`int[][] array2D = new int[2][2];`

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

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

All of the above.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How do you access the first element in the second row of a 2D array named `array2D`?

`array2D[1][0];`

`array2D[0][1];`

`array2D[2][1];`

`array2D[1][1];`

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does `array2D.length` return for a 2D array named `array2D`?

The number of columns in the array.

The number of rows in the array.

The total number of elements in the array.

The length of the first row.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How would you iterate through all elements of a 2D array named `array2D` using a nested for loop?

`for(int i = 0; i < array2D.length; i++) { for(int j = 0; j < array2D[i].length; j++) { // access element } }`

`for(int i = 0; i < array2D.length; i++) { for(int j = 0; j < array2D.length; j++) { // access element } }`

`for(int i = 0; i < array2D[0].length; i++) { for(int j = 0; j < array2D.length; j++) { // access element } }`

`for(int i = 0; i < array2D.length; i++) { for(int j = 0; j < array2D[0].length; j++) { // access element } }`

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct way to pass a 2D array named `array2D` to a method in Java?

`public void processArray(int[][] array2D) { // process array }`

`public void processArray(int array2D[][]) { // process array }`

`public void processArray(int[] array2D[]) { // process array }`

All of the above.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following statements will correctly create a 2D array with 3 rows and 2 columns?

`int[][] array2D = new int[3][2];`

`int array2D[][] = new int[2][3];`

`int[] array2D = new int[3][2];`

`int[][] array2D = new int[][3];`

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?