LPU Java Unit 1 Lecture 7 MCQ Operators | LPUCOLAB

LPU Java Unit 1 Lecture 7 MCQ Operators | LPUCOLAB

LPU_Java_Unit 1_Lecture 7_MCQ_Operators

1. What is the output of the following code?

class Main {
    public static void main(String args[]) {
        int four = 4;
        int three = 3;
        int total = four + (four > 6 ? ++three : --three);
        System.out.println(total);
    }
}

Answer:
6


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

class Main {
    public static void main(String args[]) {     
        int g = 3;
        System.out.print(++g * 8);
    }
}

Answer:
32


3. What will be the output of the given code?

class Main {
    public static void main(String args[]) {     
        int var1 = 5; 
        int var2 = 6; 
        int var3; 
        var3 = ++var2 * var1 / var2 + var2;                 
        System.out.print(var3);
    }
}

Answer:
12


4. What will be the output of the given code?

class Main {
    public static void main(String args[]) {     
        int a = 5 + 5 * 2 + 2 * 2 + (2 * 3);
        System.out.println(a);
    }
}

Answer:
25


5. What will be the output of the given code?

class Main {
    public static void main(String args[]) {     
        int value = 21, sum = 5 + --value;
        int data = --value + ++value / sum++ * value++ + ++sum  % value--;
        System.out.println(data);
    }
}

Answer:
25