Welcome to the Java Array Coding Quiz. In this quiz, we present 10 coding MCQ questions to test your coding knowledge on the Java Array topic. Each question has a correct and brief explanation.
1. What is the output of the following Java code snippet?
int[] array = {1, 2, 3, 4, 5};
System.out.println(array[2]);
a) 1
b) 2
c) 3
d) 4
2. What does this Java code snippet output?
int[] numbers = new int[5];
System.out.println(numbers[3]);
a) 0
b) 3
c) 4
d) Null
3. Identify the output of the following code:
int[] nums = {1, 2, 3, 4, 5};
for (int i = 0; i < nums.length; i++) {
nums[i] = nums[i] * 2;
}
System.out.println(nums[2]);
a) 3
b) 4
c) 6
d) 8
4. What will be printed by this Java code?
int[] array = new int[]{1, 2, 3, 4, 5};
System.out.println(array[array.length - 1]);
a) 1
b) 4
c) 5
d) An error
5. What does this code snippet output?
int[][] matrix = {{1, 2}, {3, 4}, {5, 6}};
System.out.println(matrix[1][1]);
a) 2
b) 3
c) 4
d) 6
6. What is the result of executing this code?
int[] numbers = {1, 2, 3, 4, 5};
System.out.println(numbers[numbers.length]);
a) 1
b) 5
c) An ArrayIndexOutOfBoundsException
d) Null
7. What will the following Java code snippet output?
int[] array = {1, 2, 3, 4, 5};
int[] anotherArray = array;
anotherArray[0] = 10;
System.out.println(array[0]);
a) 1
b) 10
c) 2
d) An error
8. What does the following code snippet print?
int[] numbers = {1, 2, 3, 4, 5};
int sum = 0;
for (int number : numbers) {
sum += number;
}
System.out.println(sum);
a) 10
b) 15
c) 20
d) 25
9. Determine the output of this Java code:
int[] values = new int[3];
values[0] = 10;
values[1] = 20;
System.out.println(values[2]);
a) 0
b) 10
c) 20
d) Null
10. What is the result of the following code snippet?
int[] arr = {1, 2, 3, 4, 5};
int x = arr[1] + arr[4];
System.out.println(x);
a) 3
b) 6
c) 7
d) 9
Comments
Post a Comment
Leave Comment