LPU Java Unit 1 Lecture 8 MCQ Conditional Statements | LPUCOLAB

LPU Java Unit 1 Lecture 8 MCQ Conditional Statements | LPUCOLAB

LPU_Java_Unit 1_Lecture 8_MCQ_Conditional Statements

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

public class Main {
    public static void main(String args[]) {     
        int x = 20;
        int y = 10;
        if (x > y && y > 10) {
            System.out.print(y);
        } else {
            System.out.print(x);
        }
    }
}

Solution:

20


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

public class Main {
    public static void main(String[] args){
        int x = 10; 
        if (x) {
            System.out.println("Stark");
        }
        else { 
            System.out.println("X"); 
        } 
    }
}

Solution:

Compile Time Error


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

public class Main {
    public static void main(String[] args){
        boolean t = true; 
        System.out.println("NeoX"); 
        if(t) 
            return; 
        System.out.println("NeoStark");
    }
}

Solution:

NeoX


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

public class Main {
    public static void main(String[] args){
        boolean name = true;
        switch (name) {
            case true:
                System.out.println("Hello ");
            default:
                System.out.println("hi");
        }
    }
}

Solution:

Compile Time Error


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

public class Main {
    public static void main(String[] args){
        int x = 10, y = 20; 
        if (false);
    }
}

Solution:

No Output