Java - MCQ

Multiple Choice Questions


Share with a Friend

 

Java MCQ - Methods and Arrays - Set 29

6. What will be the output of the following Java 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/2;
                array_variable[i]++;
                System.out.print(array_variable[i] + " ");
                i++;
            }
 
        } 
    }
A). 0 2 4 6 8
B). 1 2 3 4 5
C). 0 1 2 3 4 5 6 7 8 9
D). 1 2 3 4 5 6 7 8 9 10
View Answer
Correct: B



7. What will be the output of the following Java program, if we run as “java main_arguments 1 2 3”?

    class main_arguments 
    {
        public static void main(String [] args) 
        {
            String [][] argument = new String[2][2];
            int x;
            argument[0] = args;
            x = argument[0].length;
            for (int y = 0; y < x; y++) 
                System.out.print(" " + argument[0][y]);              
        }
    }
A). 1 1
B). 1 0
C). 1 0 3
D). 1 2 3
View Answer
Correct: D



8. Which will legally declare, construct, and initialize an array?
A). int [] myList = {"1", "2", "3"};
B). int [] myList = (5, 8, 2);
C). int myList [] [] = {4,9,7,0};
D). int myList [] = {4, 3, 7};
View Answer
Correct: D



9. Which three are legal array declarations?

1. int [] myScores [];
2. char [] myChars;
3. int [6] myScores;
4. Dog myDogs [];
5. Dog myDogs [7];
A). 1, 2, 4
B). 2, 4, 5
C). 2, 3, 4
D). All are correct.
View Answer
Correct: A



10. Which one of the following will declare an array and initialize it with five numbers?
A). Array a = new Array(5);
B). int [] a = {23,22,21,20,19};
C). int a [] = new int[5];
D). int [5] array;
View Answer
Correct: B



 
 
 
   
   
   
UltraInfo Technologies
ITDeveloper