Computer Applications
Differentiate between if else if and switch-case statements
Java Conditional Stmts
ICSE 2019
50 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
35 Likes
Related Questions
The relative velocity of two trains travelling in opposite directions is calculated by adding their velocities. In case, the trains are travelling in the same direction, the relative velocity is the difference between their velocities. Write a program to input the velocities and length of the trains. Write a menu driven program to calculate the relative velocities and the time taken to cross each other.
Which of the following is true about the
default
label in aswitch
statement?Using the switch-case statement, write a menu driven program to do the following:
(a) To generate and print Letters from A to Z and their Unicode
Letters Unicode A 65 B 66 . . . . . . Z 90 (b) Display the following pattern using iteration (looping) statement:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5Which of the following data type cannot be used with switch case construct?
- int
- char
- String
- double