Computer Applications
Differentiate between if else if and switch-case statements
Java Conditional Stmts
ICSE 2019
53 Likes
Answer
if else if | switch-case |
---|---|
if else if can test for any Boolean expression like less than, greater than, equal to, not equal to, etc. | switch-case can only test if the expression is equal to any of its case constants. |
if else if can use different expression involving unrelated variables in its different condition expressions. | switch-case statement tests the same expression against a set of constant values. |
Answered By
36 Likes
Related Questions
Ravi runs the following Java code but encounters an error. Identify the statement causing the issue, correct it, and ensure the output is "Hungry".
char h = 'Y'; if (h == 'y' || 'Y') System.out.println("Hungry"); else System.out.println("Not Hungry");
Choose the correct equivalent of the given if-else statement:
if(x % 2 == 0) System.out.println("Even"); else System.out.println("Odd");
A triangle is said to be an 'Equable Triangle', if the area of the triangle is equal to its perimeter. Write a program to enter three sides of a triangle. Check and print whether the triangle is equable or not.
For example, a right angled triangle with sides 5, 12 and 13 has its area and perimeter both equal to 30.Rewrite the following code using single if else statement:
if (brd.equals("ICSE")) { if (code == 86) { System.out.println("ICSE Computer Applications"); } else { System.out.println("Unknown subject"); } } else { System.out.println("Unknown subject"); }