Mu Net-android engineer first form -4-3 Java conditional statement Multiple if

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.