Rewrite the following code using switch case statement

if (value == 1) {
    System.out.println("1st division");
} else if (value == 2) {
    System.out.println("2nd division");
} else if (value == 3) {
    System.out.println("3rd division");
} else {
    System.out.println("Wrong choice");
}

Single Choice
Views 47

Answer:


switch (value) {
    case 1:
        System.out.println("1st division");
        break;
    case 2:
        System.out.println("2nd division");
        break;
    case 3:
        System.out.println("3rd division");
        break;
    default:
        System.out.println("Wrong choice");
        break;
}

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.