Computer Applications
Differentiate between if else if and switch-case statements
Java Conditional Stmts
ICSE 2019
56 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
The statement that brings the control back to the calling method is:
- break
- System.exit(0)
- continue
- return
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.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.
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.