Complete the code to declare an array of integers with size 5.
int[] numbers = new int[[1]];The array size is set to 5, so it can hold 5 integer elements indexed from 0 to 4.
Complete the code to access the third element of the array named 'data'.
int value = data[[1]];Array indices start at 0, so the third element is at index 2.
Fix the error in the code to correctly initialize an array with values 1, 2, 3.
int[] arr = [1] {1, 2, 3};
When initializing an array with values, you must use 'new int[]' before the curly braces.
Fill both blanks to create a loop that prints all elements of an array named 'arr'.
for (int i = [1]; i [2] arr.length; i++) { System.out.println(arr[i]); }
The loop starts at index 0 and runs while i is less than arr.length to avoid going out of bounds.
Fill all three blanks to create a method that returns the sum of all elements in an integer array named 'nums'.
public int sumArray(int[] nums) {
int sum = [1];
for (int i = [2]; i [3] nums.length; i++) {
sum += nums[i];
}
return sum;
}Initialize sum to 0, start loop at 0, and loop while i is less than nums.length to sum all elements.
