Multiple else if statements

public class demo { 

public static void main(String[] args) { 
boolean examIsDone = true; 
int score = 65; 
if (examIsDone) 
if (score >= 90)System.out.println("A ,Excellent"); 
else if (score >= 80) 
System.out.println("B ,Good"); 
else if (score >= 70) 
System.out.println("C ,Middle"); 
else if (score >= 60) 
System.out.println("D ,Pass"); 

else 
System.out.println("E ,Fail"); 


System.out.println("Done is Done"); 

} 
} 

1), it can not be omitted parentheses after the if, the final value of the expression in parentheses must return a Boolean value
2) If only one statement in vivo conditions need to be performed, then if the back brace can be omitted, but this is a very bad programming practice.
3), for a given if, else statement is optional, else if statement is optional
4), when else and else if occur simultaneously, else must appear after the else if
5) where there are multiple else if statements occur simultaneously, so if there is a statement of expression else if the test is successful, it will ignore all other else if and else branches.
6) If more than if occurs, only one else's situation, else clause is attributable to the innermost if statement

Intelligent Recommendation

C# Programming Fundamentals - Project 1: Attractions Ticket Cashier System - Practice Switch Statements, Nested Statements, Use of Multiple If-else Statements

Knowledge points:Switch statements, nested statements, multiple if-else statements. Statement of needs:Tickets for scenic spots are subject to low season ticket prices. From January to June in the off...

Java process control statements if, if else, if...else if...else

1.1 ifStatement: ifSentence means that if a certain condition is met, a certain process is performed.   operation result: 1.2 if…elseStatement: if…elseA sentence means tha...

Objects and switch or if/else statements

Objects, like dictionaries, can be used to store key/value pairs. If your data is the same as an object, you can use the object to find the value you want instead of using a switch or if/else statemen...

130-if else statements

Branch -if statement if else grammar if(<test>) <code executed if <test> is true> else <code executed if <test> is false> If and else if the code to be executed multiple ...

More Recommendation

determining if-else statements

<1> if-else format using  Demo Output: Have a ticket, you can train Finally see Ta, and flattered ~ ~ ~...

16-if else statements

if else statements if-else conditional structure A structure: if (conditional expression) { statement execution } Structure II: Choose one if (conditional expression) { execute statement 1 }else{ exec...

Interpretation beginInvoke in if else statements

We commonly used control (that is, the main thread) and delegate (delegate) to invoke and use beginivoke. Here I would like to talk about invoke, the difference between begininvoke:   Control of ...

4.3 if-else statements use

Q: Yes Results dividing the input register.   ...

2.4.1, if-then and if-then-else statements

if-then and if-then-else statements if-then statement if-then statement is the most basic control flow statement. It will tell the program to only certain portions of the test results is true if the c...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top