Rewrite the following program using Switch:
if (x == 1) {
system.out.println("x is 1");
}
else if (x == 2) {
system.out.println("x is 2");
}
else {
system.out.println( "value of x unknown"); }
switch(x)
{
case 1:
System.out.println("x is 1");
break;
case 2:
System.out.println("x is 2");
break;
default:
System.out.println("value of x unknown");
}
Comments
Leave a comment