1 Crore+ students have signed up on EduRev. Have you? Download the App |
Which of the following statements about multidimensional arrays in Java is true?
What will be the output of the following code?
int[] numbers = {1, 2, 3, 4, 5};
System.out.println(numbers[3]);
What will be the output of the following code?
int[] values = new int[5];
System.out.println(values[2]);
What will be the output of the following code?
int[] numbers = new int[3];
System.out.println(numbers.length);
What will be the output of the following code?
int[] numbers = {1, 2, 3, 4, 5};
System.out.println(numbers[numbers.length - 1]);
What will be the output of the following code?
int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
System.out.println(matrix[1][2]);
What will be the output of the following code?
int[] numbers = {1, 2, 3, 4, 5};
int sum = 0;
for (int i = 0; i < numbers.length; i++) {
sum += numbers[i];
}
System.out.println(sum);
What will be the output of the following code?
int[] array = {1, 2, 3, 4, 5};
int max = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
System.out.println(max);
What will be the output of the following code?
int[] array = {5, 10, 15, 20};
int target = 15;
int index = -1;
for (int i = 0; i < array.length; i++) {
if (array[i] == target) {
index = i;
break;
}
}
System.out.println(index);
What will be the output of the following code?
int[] array = {1, 2, 3, 4, 5};
int target = 6;
boolean found = false;
for (int i = 0; i < array.length; i++) {
if (array[i] == target) {
found = true;
break;
}
}
System.out.println(found);
What will be the output of the following code?
int[] array = {2, 4, 6, 8, 10};
int target = 5;
int count = 0;
for (int i = 0; i < array.length; i++) {
if (array[i] % 2 == 0) {
count++;
}
}
System.out.println(count);
60 videos|37 docs|12 tests
|
60 videos|37 docs|12 tests
|