Computer Applications
Differentiate between if else if and switch-case statements
Java Conditional Stmts
ICSE 2019
58 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
37 Likes
Related Questions
Which of the following data type cannot be used with switch case construct?
- int
- char
- String
- double
The statement that brings the control back to the calling method is:
- break
- System.exit(0)
- continue
- return
Which of the following is not true with regards to a switch statement?
- checks for an equality between the input and the case labels
- supports floating point constants
- break is used to exit from the switch block
- case labels are unique
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.