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>=70&&SCORE<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