Challenge - 5 Problems
Array Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate2:00remaining
Output of array element modification
What is the output of this Java code snippet?
Java
public class Main { public static void main(String[] args) { int[] arr = {1, 2, 3, 4, 5}; arr[2] = arr[0] + arr[4]; System.out.println(arr[2]); } }
Attempts:
2 left
💻 code output
intermediate2:00remaining
Sum of array elements
What is the output of this Java program?
Java
public class Main { public static void main(String[] args) { int[] numbers = {10, 20, 30, 40}; int sum = 0; for (int i = 0; i < numbers.length; i++) { sum += numbers[i]; } System.out.println(sum); } }
Attempts:
2 left
🔧 debug
advanced2:00remaining
Identify the error in array access
What error does this Java code produce when run?
Java
public class Main { public static void main(String[] args) { int[] arr = new int[3]; arr[3] = 10; System.out.println(arr[3]); } }
Attempts:
2 left
💻 code output
advanced2:00remaining
Output after array element swap
What is the output of this Java program?
Java
public class Main { public static void main(String[] args) { int[] arr = {7, 8, 9}; int temp = arr[0]; arr[0] = arr[2]; arr[2] = temp; for (int i = 0; i < arr.length; i++) { System.out.print(arr[i] + " "); } } }
Attempts:
2 left
🧠 conceptual
expert2:00remaining
Number of elements after array initialization
How many elements does the array contain after this declaration?
int[] arr = new int[5];
Attempts:
2 left
