Computer Applications

Write the following switch statement by using nested if statements:

switch (choice)
{
case 0:
case 1:
 x = 111;
 y = 222; 
 break;
case 2:
 x = 333;
 y = 444; 
 break;
case 3:
 x = -11;
 y = -22; 
 break;
default:
 y = 555;
}

Java Conditional Stmts

4 Likes

Answer


if (choice == 0 || choice == 1)
{
  x = 111;
  y = 222;
}
else
{
  if (choice == 2)
  {
    x = 333;
    y = 444;
  }
  else
  {
    if (choice == 3)
    {
      x = -11;
      y = -22;
    }
    else
    {
      y = 555;
    }
  }
}

Answered By

3 Likes


Related Questions