Computer Applications
Convert the following if else if construct into switch case:
if (ch== 'c' || ch=='C')
System.out.print("COMPUTER");
else if (ch == 'h' || ch =='H')
System.out.print("HINDI");
else
System.out.print("PHYSICAL EDUCATION");
Java Conditional Stmts
74 Likes
Answer
switch (ch) {
case 'c':
case 'C':
System.out.print("COMPUTER");
break;
case 'h':
case 'H':
System.out.print("HINDI");
break;
default:
System.out.print("PHYSICAL EDUCATION");
}
Answered By
41 Likes
Related Questions
Write a Java program to print name, purchase amount and final payable amount after discount as per given table:
Purchase Amount Discount upto ₹10000/- 15% ₹10000 to ₹ 20000/- 20% Above ₹20000/- 30% Rewrite the following code using single if statement.
if(code=='g') System.out.println("GREEN"); else if(code=='G') System.out.println("GREEN");The statement that brings the control back to the calling method is:
- break
- System.exit(0)
- continue
- return
Write a program to input three numbers (positive or negative). If they are unequal then display the greatest number otherwise, display they are equal. The program also displays whether the numbers entered by the user are 'All positive', 'All negative' or 'Mixed numbers'.
Sample Input: 56, -15, 12
Sample Output:
The greatest number is 56
Entered numbers are mixed numbers.