Challenge - 5 Problems
Array Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Array Initialization and Access
What is the output of the following Java code snippet?
DSA Java
public class Main { public static void main(String[] args) { int[] arr = new int[3]; arr[0] = 5; arr[1] = 10; arr[2] = 15; System.out.print(arr[1] + ", " + arr[2]); } }
Attempts:
2 left
💡 Hint
Remember array indexing starts at 0 in Java.
✗ Incorrect
The array elements are assigned as arr[0]=5, arr[1]=10, arr[2]=15. Accessing arr[1] and arr[2] prints 10 and 15 respectively.
❓ Predict Output
intermediateOutput of Array Declaration with Initialization
What will be printed by this Java program?
DSA Java
public class Main { public static void main(String[] args) { int[] numbers = {1, 2, 3, 4}; System.out.print(numbers.length); } }
Attempts:
2 left
💡 Hint
Check the number of elements inside the curly braces.
✗ Incorrect
The array 'numbers' has 4 elements, so numbers.length is 4.
❓ Predict Output
advancedOutput of Multi-dimensional Array Initialization
What is the output of this Java code?
DSA Java
public class Main { public static void main(String[] args) { int[][] matrix = new int[2][2]; matrix[0][0] = 1; matrix[0][1] = 2; matrix[1][0] = 3; matrix[1][1] = 4; System.out.print(matrix[1][0] + ", " + matrix[0][1]); } }
Attempts:
2 left
💡 Hint
Remember the first index is the row, second is the column.
✗ Incorrect
matrix[1][0] is 3 and matrix[0][1] is 2, so output is '3, 2'.
❓ Predict Output
advancedOutput of Array Initialization with Default Values
What will this Java program print?
DSA Java
public class Main { public static void main(String[] args) { boolean[] flags = new boolean[3]; System.out.print(flags[0] + ", " + flags[1] + ", " + flags[2]); } }
Attempts:
2 left
💡 Hint
What is the default value for boolean arrays in Java?
✗ Incorrect
Boolean arrays are initialized with false by default.
🧠 Conceptual
expertUnderstanding Array Initialization Behavior
Which statement about array declaration and initialization in Java is correct?
Attempts:
2 left
💡 Hint
Think about default values and array resizing in Java.
✗ Incorrect
In Java, arrays created with 'new' have default values (0 for numbers, false for booleans). Arrays cannot be resized after creation. Arrays initialized with curly braces do not require size specification.
