KnowledgeBoat Logo

Computer Applications

switch case construct into if-else-if :

switch (n)
{
case 1: 
s=a+b; 
System.out.println("Sum="+s);
break; 
case 2: 
d=a-b; 
System.out.println("Difference="+d);
break: 
case 3: 
p=a*b; 
System.out.println("Product="+p);
break; 
default: 
System.out.println("Wrong Choice!");
}

Java Conditional Stmts

61 Likes

Answer

if (n == 1) {
    s = a + b;
    System.out.println("Sum="+s);
}
else if (n == 2) {
    d = a - b; 
    System.out.println("Difference="+d);
}
else if (n == 3) {
    p = a * b; 
    System.out.println("Product="+p);
}
else {
    System.out.println("Wrong Choice!");
}

Answered By

42 Likes


Related Questions