Computer Applications
Write two differences between if-else-if and switch-case statements.
Java Conditional Stmts
12 Likes
Answer
Two differences between if-else-if and switch-case statements are:
- switch-case statement can only test for equality whereas if-else-if can test for any Boolean expression.
- switch-case tests the same expression against constant values while if-else-if can use different expression involving unrelated variables.
Answered By
5 Likes
Related Questions
Rewrite the following code using single if statement.
if(code=='g') System.out.println("GREEN"); else if(code=='G') System.out.println("GREEN");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.