Challenge - 5 Problems
Array Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate2:00remaining
Output of array sum calculation
What is the output of this Java code that sums all elements in an integer array?
Java
int[] numbers = {2, 4, 6, 8}; int sum = 0; for (int num : numbers) { sum += num; } System.out.println(sum);
Attempts:
2 left
💻 code output
intermediate2:00remaining
Output of array reverse print
What does this Java code print when it prints the array elements in reverse order?
Java
int[] arr = {1, 3, 5, 7}; for (int i = arr.length - 1; i >= 0; i--) { System.out.print(arr[i] + " "); }
Attempts:
2 left
💻 code output
advanced2:30remaining
Output of array element replacement
What is the output after replacing all negative numbers with zero in this array?
Java
int[] data = {4, -1, 7, -3, 0}; for (int i = 0; i < data.length; i++) { if (data[i] < 0) { data[i] = 0; } } for (int num : data) { System.out.print(num + " "); }
Attempts:
2 left
💻 code output
advanced2:30remaining
Output of array copy with System.arraycopy
What is the output of this code that copies part of one array into another?
Java
int[] source = {10, 20, 30, 40, 50}; int[] dest = {1, 2, 3, 4, 5}; System.arraycopy(source, 1, dest, 2, 2); for (int i : dest) { System.out.print(i + " "); }
Attempts:
2 left
🧠 conceptual
expert2:00remaining
Error type when accessing invalid array index
What error does this Java code produce when trying to access an invalid index in an array?
Java
int[] arr = {5, 10, 15}; System.out.println(arr[5]);
Attempts:
2 left
