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