English

Convert the following construct as directed: 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 - Computer Applications

Advertisements
Advertisements

Question

Convert the following construct as directed:

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!"); 
}
Answer in Brief

Solution

if (n == 1)
{s = a + b;
System.out.printIn("Sum = " + s);
}
else if (n == 2)
{d = a − b;
System.out.printIn("Difference = " + d);
}
else if (n == 3)
{p = a * b;
System.out.printin("Product = " + p);
}
else
System.out.printIn("Wrong Choice");
}
shaalaa.com
  Is there an error in this question or solution?
Chapter 1.08: Conditional Statements in Java - EXERCISES [Page 99]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 1.08 Conditional Statements in Java
EXERCISES | Q IV. 1. | Page 99
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×