ICSE Class 10 Computer Applications
Question 8 of 43
Conditional Constructs in Java — Question 8
Back to all questions 8
Question Question 8
Rewrite the following if statement, using the switch statement:
if (choice == 1)
System.out.println("You selected One");
else if (choice == 2)
System.out.println("You selected Two");
else if (choice == 3)
System.out.println("You selected Three");
else if (choice == 4)
System.out.println("You selected Four");
else if (choice == 5)
System.out.println("You selected Five");
else if (choice == 6)
System.out.println("You selected Six");
else
System.out.println("Invalid choice");switch (choice) {
case 1:
System.out.println("You selected One");
break;
case 2:
System.out.println("You selected Two");
break;
case 3:
System.out.println("You selected Three");
break;
case 4:
System.out.println("You selected Four");
break;
case 5:
System.out.println("You selected Five");
break;
case 6:
System.out.println("You selected Six");
break;
default:
System.out.println("Invalid choice");
}