AlgoMaster Logo

Arrays - Quiz

Last Updated: January 3, 2026

Arrays Exercises

31 quizzes

1
Code Completion

Access the last element of the scores array using its length

java
1
int lastScore = scores[ - 1];

Click an option to fill the blank:

2
Code Completion

Quickly create an int array with three default-initialized elements

java
1
int[] values = int[3];

Click an option to fill the blank:

3
Code Completion

Fill the monthlySales array with zeros in a single statement

java
1
java.util.Arrays.(monthlySales, 0);

Click an option to fill the blank:

4
Multiple Choice

Which declaration correctly creates an array that can hold 10 double temperature readings?

5
Multiple Choice

What happens if you access numbers[5] in an int[] numbers = new int[5]; array?

6
Multiple Choice

Which operation is a typical use case for a linear search on an array?

7
Multiple Choice

For binary search on an int[] using your own implementation, what must be true?

8
Multiple Choice

How do you access the number of rows in a 2D int[][] matrix?

9
Multiple Choice

In a jagged int[][] arr, what does arr[1].length represent?

10
Multiple Choice

Which Arrays class method converts an int[] to a readable String?

11
Multiple Choice

Which method would you use to copy only the first 3 elements of an int[] source into a new int[]?

12
Multiple Choice

What is a key advantage of System.arraycopy over manual copying in a loop?

13
Multiple Choice

Which statement about Arrays.equals(int[], int[]) is correct?

14
Multiple Choice

Why might you create a copy of an int[] before sorting it?

15
Sequencing

Order the steps to search for a username in a sorted String[] using binary search you implement yourself.

Drag and drop to reorder, or use the arrows.

16
Sequencing

Order the steps to create and use a 2D int array for a game board.

Drag and drop to reorder, or use the arrows.

17
Output Prediction

What is the output of this code?

1int[] scores = {10, 20, 30, 40};
2int index = 1;
3int result = scores[index] + scores[index + 2];
4System.out.println(result);
18
Output Prediction

What is the output of this code?

1int[][] grid = {
2    {1, 2},
3    {3, 4}
4};
5int value = grid[0][1] * grid[1][0];
6System.out.println(value);
19
Output Prediction

What is the output of this code?

1int[] data = {5, 3, 9, 1};
2java.util.Arrays.sort(data);
3System.out.println(data[0] + ":" + data[data.length - 1]);
20
Output Prediction

What is the output of this code?

1int[] original = {2, 4, 6};
2int[] copy = java.util.Arrays.copyOf(original, 2);
3copy[0] = 10;
4System.out.println(original[0] + "," + copy[0]);
21
Output Prediction

What is the output of this code?

1int[] a = {1, 2, 3};
2int[] b = a;
3b[1] = 99;
4System.out.println(a[0] + a[1] + a[2]);
22
Bug Spotting

Find the bug in this code that initializes and prints a 2D array of seats.

Click on the line(s) that contain the bug.

java
1
public class Theater {
2
    public static void main(String[] args) {
3
        int[][] seats = new int[3][];
4
        for (int row = 0; row < seats.length; row++) {
5
            for (int col = 0; col < seats[row].length; col++) {
6
                seats[row][col] = row + col;
7
            }
8
        }
9
        System.out.println(seats[0][0]);
10
    }
11
}
23
Bug Spotting

Find the bug in this code that copies sales data into a larger array.

Click on the line(s) that contain the bug.

java
1
public class SalesCopy {
2
    public static void main(String[] args) {
3
        int[] monthly = {10, 20, 30};
4
        int[] yearly = new int[12];
5
        System.arraycopy(yearly, 0, monthly, 0, monthly.length);
6
        System.out.println(java.util.Arrays.toString(yearly));
7
    }
8
}
24
Matching

Match each Arrays class method with its primary purpose.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

25
Matching

Match the array-related concept with its best description.

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

26
Fill in the Blanks

Complete the code to create a copy of an int array and sort the copy without changing the original.

java
1
int[] original = {5, 2, 9, 1};
2
int[] = java.util.Arrays.copyOf(original, original.);
3
java.util.Arrays.();
4
System.out.println(java.util.Arrays.toString());

Click an option to fill blank 1:

27
Fill in the Blanks

Complete the code to create and use a 2D int array for storing pixel brightness values.

java
1
int[][] pixels = new int[][];
2
pixels[0][0] = 255;
3
System.out.println(pixels. + "x" + pixels[0].);

Click an option to fill blank 1:

28
Fill in the Blanks

Complete the code to perform a linear search on an int array for a target value.

java
1
int[] nums = {3, 7, 9, 2};
2
int target = 9;
3
int foundIndex = -1;
4
for (int i = 0; i < nums.; i++) {
5
if (nums[i] == ) {
6
foundIndex = i;
7
break;
8
}
9
}
10
System.out.println(foundIndex);

Click an option to fill blank 1:

29
Fill in the Blanks

Complete the code to copy part of an int array using System.arraycopy.

java
1
int[] source = {1, 2, 3, 4, 5};
2
int[] dest = new int[3];
3
System.(source, 1, dest, 0, );
4
System.out.println(java.util.Arrays.toString(dest));

Click an option to fill blank 1:

30
Hotspot Selection

Click the line that will cause an ArrayIndexOutOfBoundsException at runtime.

Click on the line to select.

java
1
int[] values = new int[3];
2
values[0] = 10;
3
values[2] = 30;
4
int x = values[3];
5
System.out.println(x);
31
Hotspot Selection

Click the line that will throw a NullPointerException when executed.

Click on the line to select.

java
1
int[][] data = new int[2][];
2
data[0] = new int[3];
3
int sum = data[1][0];
4
System.out.println(sum);