Complete the code to declare an array of integers with size 5.
int[] numbers = new int[[1]];The array size must be a positive integer. Here, 5 means the array can hold 5 integers.
Complete the code to assign the value 10 to the first element of the array.
numbers[[1]] = 10;
Array indexes start at 0 in Java, so the first element is at index 0.
Fix the error in the code to print the length of the array.
System.out.println(numbers[1]);In Java, arrays have a field called length (without parentheses) to get their size.
Fill both blanks to create a loop that prints all elements in the array.
for (int i = [1]; i [2] numbers.length; i++) { System.out.println(numbers[i]); }
The loop starts at index 0 and runs while i is less than the array length to avoid going out of bounds.
Fill all three blanks to create an array of size 3, assign values, and print the second element.
int[] arr = new int[[1]]; arr[0] = [2]; System.out.println(arr[[3]]);
The array size is 3, the first element is assigned 7, and the second element (index 1) is printed.
