Article From:https://www.cnblogs.com/MrTanJunCai/p/9906728.html

***************************Chapter III Process Control**************************************************************************

Classification of process control statements:

I. Sequential Statements

2. Branch statement (conditional statement)

III. Loop Statements

 

***************************Sequential sentence ********************************************************************

Execute from top to bottom in the order in which you write code

System.out.println(“111”);
System.out.println(“222”);
System.out.println(“333”);

111
222
333

***************************Branch statement ******************************************************************

According to different conditions, executing different statements is called branching.

1.For example, when it rains, it stays in the dormitory and goes out to the movies without raining.

My sister is free. She goes to the movies. She is not free. She stays in the dormitory.

2.Ticket checking system

if(Height & lt; 120cm) {
//Release
}else{
//Ticket checking

}

Before writing a program, in order to better understand the program and sort out the programmer’s ideas, we should draw a program flow chart first.

Branches in program flow charts are diamond-shaped to indicate the conditions under which branches are written in the diamond.

 

***************************Classification of Branch Sentences ******************************************************************

One.If statement

 

if(Condition) {

//code block
}

If the condition is true, the code block is executed.

If the condition is false, it will not be carried out.

 

Ii. if..Else.

if(Condition) {

//Code block 1
}else{

//Code block 2
}

Conditions are true code block 1, otherwise code block 2 is executed

If… else… if… else

 

if(Condition) {

//Code block 1
}else if(Condition) {

//Code block 2
}else if(Condition) {

//Code block 3
}else{

//Code block 4
}

 

IV. Switch statement

switch(Condition) {

case Conditions 1: statement 1 or code block 1; break;
case Conditions 2: statement 2 or code block 2; break;
case Conditions 3: Statement 3 or code block 3; break;
default: Statement 4
}

//Jump here

break Jump out of the switch block

 

***************************ifUse of Sentences **********************************************************************

/**
Authors: zhangzy & lt; BR & gt;
Company: Blue Bridge Software College & lt; BR & gt;
Time: 2017-06-22 am
Function: Demonstrate the use of If statements
*/

import java.util.Scanner;//Tell the system where the Scanner class (mop) can be found

public class TestIf{

public static void main(String[] args){

//Needs: Give comments based on students’test scores

//Knowledge Points: How to Input in the Console
//Scanner class
//create object
//Class name object name = new class name ();
Scanner scanner = new Scanner(System.in);

//ScannerClass has a method called nextInt
//Function to receive console input when executing this method
//The console cursor flickers there waiting for user input
System.out.println(“Please enter the student’s test scores: “;
int score = scanner.nextInt();

if(score>=90){
System.out.println(“Excellent “”;
}else if(score>=80){
System.out.println(“Good “”;
}else if(score>=70){
System.out.println(“(“)”;
}else if(score>=60){
System.out.println(“Pass “”;
}else{
System.out.println(“Fail “”;
}

 

}
}

 

Link of this Article: Java Process Control (I)

Leave a Reply

Your email address will not be published. Required fields are marked *