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
Differentiate between if else if and switch-case statements
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% The statement that brings the control back to the calling method is:
- break
- System.exit(0)
- continue
- return
Rewrite the following code using single if statement.
if(code=='g') System.out.println("GREEN"); else if(code=='G') System.out.println("GREEN");