Computer Applications
Write two differences between if-else-if and switch-case statements.
Java Conditional Stmts
11 Likes
Answer
Two differences between if-else-if and switch-case statements are:
- switch-case statement can only test for equality whereas if-else-if can test for any Boolean expression.
- switch-case tests the same expression against constant values while if-else-if can use different expression involving unrelated variables.
Answered By
4 Likes
Related Questions
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
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.