Mcq On Java Array

11. What will be the output of the program?
public class Main {
public static void main(String args[]) {
int arr[] = {10, 20, 30, 40, 50};
for(int i=0; i < arr.length; i++)
{
System.out.print(" " + arr[i]);
}
}
}

A. 10 20 30 40 50
B. Compiler Error
C. 10 20 30 40
D. None of the above

View Answer


12. What will be the output of the program?
int arr[] = new int [5];
System.out.print(arr);

A. 0
B. value stored in arr[0].
C. 00000
D. Class name@ hashcode in hexadecimal form

View Answer


13.What will be the output of the program?
class array_output
{
public static void main(String args[])
{
int array_variable [] = new int[10];
for (int i = 0; i < 10; ++i)
{
array_variable[i] = i;
System.out.print(array_variable[i] + " ");
i++;
}
}
}

A. 0 2 4 6 8
B. 1 3 5 7 9
C. 0 1 2 3 4 5 6 7 8 9
D. 1 2 3 4 5 6 7 8 9 10

View Answer


14. class evaluate
{
public static void main(String args[])
{
int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n = 6;
n = arr[arr[n] / 2];
System.out.println(arr[n] / 2);
}
}

A. 3
B. 0
C. 6
D. 1

View Answer


15.Predict the output of following Java Program?
class array_output
{
public static void main(String args[])
{
char array_variable [] = new char[10];
for (int i = 0; i < 10; ++i)
{
array_variable[i] = 'i';
System.out.print(array_variable[i] + "");
}
}
}

A. 1 2 3 4 5 6 7 8 9 10
B. 0 1 2 3 4 5 6 7 8 9 10
C. i j k l m n o p q r
D. i i i i i i i i i i

View Answer


16. class Test {
public static void main(String args[]) {
int arr[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}

A. 0
0
B. garbage value
garbage value
C. Compiler Error
D. Exception

View Answer


17. class Test {
public static void main(String args[]) {
int arr[] = new int[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}


A. 0
0
B. garbage value
garbage value
C. Compiler Error
D. Exception

View Answer


18. class array_output
{
public static void main(String args[])
{
int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}};
int sum = 0;
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3 ; ++j)
sum = sum + array_variable[i][j];
System.out.print(sum / 5);
}
}

A. 8
B. 9
C. 10
D. 11

View Answer


19. What will be the output of the program?

class Test
{
public static void main (String[] args)
{
int arr1[] = {1, 2, 3};
int arr2[] = {1, 2, 3};
if (arr1 == arr2)
System.out.println("Same");
else
System.out.println("Not same");
}
}

A. Same
B. Not Same
C. Compiler error
D. None of the above

View Answer


20. What is the output of this program?
class Test
{
public static void main (String[] args)
{
int arr1[] = {1, 2, 3};
int arr2[] = {1, 2, 3};
if (arr1.equals(arr2))
System.out.println("Same");
else
System.out.println("Not same");
}
}

A. Same
B. Not Same
C. Compiler error
D. None of the above

View Answer






Also check :


Discussion


* You must be logged in to add comment.