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
32
If we use switch case statement, the above code will be,
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.");
}
Answered by
13
Answer is in the attachment hope it helps you
Attachments:
Similar questions