Computer Applications
Give two differences between the switch statement and the if-else statement.
Java Conditional Stmts
ICSE 2014
92 Likes
Answer
switch | if-else |
---|---|
switch can only test if the expression is equal to any of its case constants | if-else can test for any boolean expression like less than, greater than, equal to, not equal to, etc. |
It is a multiple branching flow of control statement | It is a bi-directional flow of control statement |
Answered By
56 Likes
Related Questions
What is a compound statement? Give an example.
Explain if-else-if construct with an example.
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.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.