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
Predict the output of the following Java program code snippet:
int m=3,n=5,p=4; if(m==n && n!=p) { System.out.println(m*n); System.out.println(n%p); } if((m!=n) || (n==p)) { System.out.println(m+n); System.out.println(m-n); }
Predict the output of the following Java program code snippet:
int a=1,b=2,c=3; switch(p) { case 1: a++; case 2: ++b; break; case 3: c--; } System.out.println(a + "," + b + "," +c);
if-else-if construct into switch case:
if(var==1) System.out.println("Distinction"); else if(var==2) System.out.println("First Division"); else if(var==3) System.out.println("Second Division"); else System.out.println("invalid");
What is meant by 'conditional' statement? Explain.