Computer Science, asked by criya0709, 5 months ago

Read the following code

if(var == 1)
System.out.println("Good");
else if(var == 2)
System.out.println("Better");
else if(var == 3)
System.out.println("Best");
else
System.out.println("Invalid");

Convert the above if else if construct into switch case. *

Answers

Answered by mkrkrishnaprasad
0

Explanation:

char c;

switch (c){

case 1:

System.out.println("Good");

break;

case 2:

System.out.println("Better");

break;

case 3:

System.out.println("Best");

break;

default:

System.out.println("Invalid");

break;

}

Answered by SƬᏗᏒᏇᏗƦƦᎥᎧƦ
28

Switch (var)

{

case 1:

System.out.println("good")

break;

case 2:

System out.println(better")

break;

case 3:

system.out.println("best")

break;

default:

System.out.println("invalid")

}

hope it helps you

Similar questions