Computer Applications
Write the following switch statement by using nested if statements:
switch (choice)
{
case 0:
case 1:
x = 11;
y = 22;
break;
case 2:
x = 33;
y = 44;
break;
default:
y = 55;
break;
}
Java Conditional Stmts
56 Likes
Answer
if (choice == 0 || choice == 1)
{
x = 11;
y = 22;
}
else
{
if (choice == 2)
{
x = 33;
y = 44;
}
else
{
y = 55;
}
}
Answered By
29 Likes
Related Questions
Format the following if statements with indentation:if (num1 != num2) {
if (num2 >= num3) x = 1; y = 2; }
else {x = 1; if (num1 == num2) z = 3;}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");
Write an if statement to find the smallest of the three given integers using the min() method of the Math class.
Using the switch statement in Java, write a program to display the colour of the spectrum (VIBGYOR) according to the user's choice.