Nested principles of conditional statements and If-else in Java

Source: Internet
Author: User

if (condition) Statement The condition in the condition statement at this point is that it needs to be enclosed in parentheses.   In fact, the conditional statements in Java are the same as in C + +. Java often wants to execute multiple statements when a condition is true. At this point, we will introduce a concept, that is, "block statement", the specific format is as follows, for reference only: { statement1 Statement2 ... } take the following example, let's try the format above! if (score>=90) System.out.println ("excellent"); The result of the desired output at this time is also a state of it! } block modules are also referred to as compound statements, where you can place multiple statements in a Java program structure where only one simple statement could have been placed. The more common cases are the same as in the examples.     title: Input scores, let the program automatically distinguish the grade corresponding to the score!
1 ImportJava.util.Scanner;2  Public classTestsum {3       /**4        * @paramargs5        */6        Public Static voidMain (string[] args) {7             //TODO auto-generated Method Stub8System.out.println ("Please enter fractions");9Scanner sc=NewScanner (system.in);Ten             intScore=sc.nextint (); One              A             if(score>=90){ -System.out.println ("excellent"); -}Else if(score>=70&&score<90){ theSystem.out.println ("Liang"); -}Else if(score>=60&&score<70){ -System.out.println ("Medium"); -}Else{ +System.out.println ("Poor"); -           } +       } A}

Nesting principles for conditional statements and If-else in Java

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.