Computer Science, asked by shikharchaudhary455, 9 months ago

Convert the following if else if construct into switch case:
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");​

Answers

Answered by anindyaadhikari13
32

If we use switch case statement, the above code will be,

<hr/>

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.");

}

<hr/>

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

Answer is in the attachment hope it helps you

Attachments:
Similar questions