Java's condition to determine
if statement contains a Boolean expression and one or more statements.
1. if a
int score = 88; if(score > 60){ System.out.println("及格"); }
Export
Passing
2. if else
50 Score = int; IF (Score> 60) { System.out.println ( "pass"); } the else { System.out.println ( "fail"); }
Export
failed
3. if ... else if ... else conditions judgment
if (Boolean expression 1) { // If the Boolean expression is true of the execution of the code 1 } else if (Boolean expression 2) { // If the Boolean expression is true of the execution of the code 2 } else if (Boolean expression formula 3) { // If the boolean expression evaluates to true execution code 3 } the else { // If the above boolean expression is true not execute code }
int score = 88; if(score > 90){ System.out.println("优秀"); }else if(score > 80){ System.out.println("良好"); }else if(score > 60){ System.out.println("及格"); }else{ System.out.println("不及格"); }
Export
Important: else if statement once one detector is true, else if other else statement are skipped and execution.
good
4. nested if
Determine whether a student fourth grade, and scores more than 60
88 Score = int; int. 4 Grade =; IF (Grade ==. 4) { IF (Score> 60) { System.out.println ( "University of fourth grade than 60, granted graduation"); } }
University of fourth grade more than 60 are allowed to graduate