Home / Questions / 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"); }
Explanatory Question

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");
}

👁 51 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation


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;
}