KnowledgeBoat Logo

Computer Applications

Explain if-else-if construct with an example.

Java Conditional Stmts

28 Likes

Answer

if-else-if construct is used to test multiple conditions and then take a decision. It provides multiple branching of control.

Below is an example of if-else-if:

if (marks < 35)
    System.out.println("Fail");
else if (marks < 60)
    System.out.println("C grade");
else if (marks < 80)
    System.out.println("B grade");
else if (marks < 95)
    System.out.println("A grade");
else
    System.out.println("A+ grade");

Answered By

17 Likes


Related Questions