ICSE Class 9 Computer Applications
Question 4 of 17
Conditional Constructs in Java — Question 4
Back to all questions 4
Question Question 4
Rewrite the following if statement, using the switch statement:
if (choice == 0)
System.out.println("You selected Blue");
else if (choice == 1)
System.out.println("You selected Cyan");
else if (choice == 2)
System.out.println("You selected Red");
else if (choice == 3)
System.out.println("You selected Magenta");
else if (choice == 4)
System.out.println("You selected Green");
else if (choice == 5)
System.out.println("You selected Yellow");
else
System.out.println("Invalid choice");switch (choice) {
case 1:
System.out.println("You selected Blue");
break;
case 2:
System.out.println("You selected Cyan");
break;
case 3:
System.out.println("You selected Red");
break;
case 4:
System.out.println("You selected Magenta");
break;
case 5:
System.out.println("You selected Green");
break;
case 6:
System.out.println("You selected Yellow");
break;
default:
System.out.println("Invalid choice");
}