Nested principles of conditional statements and If-else in Java

Source: Internet
Author: User

In Java, the format of a conditional statement is:

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!

import java.util.scanner;public class testsum {      /**        *  @param  args       */       public static void main (String[] args)  {             // todo auto-generated method  stub        system.out.println ("Please enter fractions");             scanner sc=new scanner (System.in);             int score=sc.nextint ();                          if (score>=90) {                  &nbSp System.out.println ("excellent");             }else if ( SCORE&GT;=70&AMP;&AMP;SCORE&LT;90) {             System.out.println ("Liang");           }else if (score>=60 &&score<70) {          system.out.println ("medium");           }else{             system.out.println ("poor");           }      }}


This article is from the "Sun nuo" blog, please be sure to keep this source http://10479756.blog.51cto.com/10469756/1950095

Nested principles of conditional statements and If-else in Java

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.