Source: http://www.imooc.com/code/1355
If the multiple if statement is not satisfied with condition 1, the condition 2 is judged, and the code within the Else block is executed when the preceding conditions are not true. For example, if the test score is greater than 90, then an IPHONE 5S is rewarded, and if the score is between 70 and 90, a red meter is rewarded, or 500 push-ups are punished.
Grammar:
Execution process:
Such as:
The meaning of this code is: if the score value is greater than 90, then reward an Iphone 5s, when the score value is less than or equal to 90 o'clock, first determine whether the score is greater than 70, if score is between 70--90, then reward a red meter, if the score is less than or equal to 70 , 500 push-ups will be punished.
The use of multiple if statements is very handy when the condition to be judged is a continuous interval!
Task
Small partners, together to solve an age problem.
Please apply multiple if statements in the editor, complete the code to achieve the following functions:
If the age is more than 60 years old, then the "old age", if between 40 to 60 years old, then the "middle age", if the ages between 18 to 40 years old, then the "juvenile", 18 years of age, the reminder "childhood"
Operation Result:
1 Public classHelloWorld {2 Public Static voidMain (string[] args) {3 intAge=25;4 5 if(Age >= 60) {6System.out.println ("Old age");7}Else if(Age >= && Age < 60) { 8System.out.println ("Middle-aged");9}Else if(Age >= && Age < 40) {TenSystem.out.println ("juvenile"); One}Else { ASystem.out.println ("Childhood"); - } - } the}
Mu Net-android engineer first form -4-3 Java conditional statement Multiple if