LPU Java Unit 2 Lecture 10 MCQ RB | LPUCOLAB

LPU Java Unit 2 Lecture 10 MCQ RB | LPUCOLAB

LPU_Java_Unit 2_Lecture 10_MCQ_RB

1. What will be the output of the following program?

public class Main {
    public static void main(String[] args) {
        int[] myList = {1, 5, 6, 7, 8, 9};
        int max = myList[0];
        int index = 0;
        for(int i = 1; i < myList.length; i++){
            if(myList[i] > max){
                max = myList[i];
                index = i;
            }
        }
        System.out.print(index);
    }   
}

Answer:
5


2. What will be the output of the following program?

enum Enums {
    A, B, C;
}

public class Main {
    public static void main(String[] args) {
        System.out.println(10); 
        Enums en = Enums.B;
    }
}

Answer:
10


3. What will be the output of the following program?

enum Direction {
    NORTH, EAST, SOUTH, WEST
}

public class Main {
    public static void main(String[] args) {
        System.out.println(Direction.NORTH.ordinal());
    }
}

Answer:
0


4. What will be the output of the following program?

public class Main {
    public static void main(String[] args) {
        int a1[] = new int[10];
        int a2[] = {3, 5, 7, 1, 8, 99, 44, -10};
        System.out.println("length of a1 is " + a1.length);
        System.out.println("length of a2 is " + a2.length);
    }
}

Answer:

length of a1 is 10  
length of a2 is 8

5. What will be the output of the following program?

class Main {
    public static void main(String[] args) {
        int arr[] = {1,2,3,4,5};
        int count = 0;
        for(int i = 0 ; i<5; i++ ) {
            if(arr[i]%2==0)
                count++;
        }
        System.out.print(count);
    }
}

Answer:
2