Computer Science
Write the following statement using switch case construct.
if (a==1)
{
b += 10;
System.out.println(b);
}
else if (a == 2)
{
b -= 10;
System.out.println(b);
}
else
{
b *= a;
System.out.println(b);
}
Java Conditional Stmts
8 Likes
Answer
switch (a) {
case 1:
b += 10;
System.out.println(b);
break;
case 2:
b -= 10;
System.out.println(b);
break;
default:
b *= a;
System.out.println(b);
}
Answered By
5 Likes
Related Questions
Rewrite the following using for loop:
a=1; while(a<=5) {b = 1; while(b<=a) { System.out.print(b); b++; } System.out.println(); a++; }
State the final value of q at the end of the following program segment after execution. Show the dry run.
for(m=2;m<=3;++m) { for(n=1;n<=m;++n) { p=m+n-1; if(p%3 == 0) q += p; else q += p+4; } }
What is meant by statement? Name the different types of statements which are used in Java programming.
Write short notes on Control statement