Computer Applications

Convert the following if else if construct into switch case:

if (ch== 'c' || ch=='C')
System.out.print("COMPUTER");
else if (ch == 'h' || ch =='H')
System.out.print("HINDI");
else
System.out.print("PHYSICAL EDUCATION");

Java Conditional Stmts

74 Likes

Answer

switch (ch) {
    case 'c':
    case 'C':
        System.out.print("COMPUTER");
        break;
    case 'h':
    case 'H':
        System.out.print("HINDI");
        break;
    default:
        System.out.print("PHYSICAL EDUCATION");

}

Answered By

41 Likes


Related Questions