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
An air-conditioned bus charges fare from the passengers based on the distance travelled as per the tariff given below:
Distance Travelled Fare Up to 10 km Fixed charge ₹80 11 km to 20 km ₹6/km 21 km to 30 km ₹5/km 31 km and above ₹4/km Design a program to input distance travelled by the passenger. Calculate and display the fare to be paid.
Differentiate between if else if and switch-case statements
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.