Computer Applications
Explain if-else-if construct with an example.
Java Conditional Stmts
28 Likes
Answer
if-else-if construct is used to test multiple conditions and then take a decision. It provides multiple branching of control.
Below is an example of if-else-if:
if (marks < 35)
System.out.println("Fail");
else if (marks < 60)
System.out.println("C grade");
else if (marks < 80)
System.out.println("B grade");
else if (marks < 95)
System.out.println("A grade");
else
System.out.println("A+ grade");
Answered By
17 Likes
Related Questions
When does Fall through occur in a switch statement? Explain.
What is a compound statement? Give an example.
Give two differences between the switch statement and the if-else statement.
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.