KnowledgeBoat Logo
LoginJOIN NOW

Computer Applications

Convert the following if else if construct into switch case:

if (a == 10)
    System.out.println("TEN");
else if (a == 50)
    System.out.println("FIFTY");
else if (a == 100)
    System.out.println("HUNDRED");
else
    System.out.println("UNKNOWN");

Java Conditional Stmts

27 Likes

Answer

switch (a) {
    case 10:
    System.out.println("TEN");
    break;

    case 50:
    System.out.println("FIFTY");
    break;

    case 100:
    System.out.println("HUNDRED");
    break;

    default:
    System.out.println("UNKNOWN");
}

Answered By

9 Likes


Related Questions