1. What is the execution structure of a Java statement
Program flow control.
2. What are the structure of Java statements
There are three types of structures:
Sequential structure (execution code from top to bottom line of the program, no judgment and relay)
Select structure (conditional statement)
Loop structure: Loop statement function (recurring execution of specific code if the recycle condition is met)
Circular statement Classification (for loop while loop Do/while loop)
For Loop statement format: for (initialization expression 1; Loop field expression 2; post-loop expression)
{
Loop statement body;
}
The specific code is as follows:
public class Demo10
{
public static void Main (String[]args)
{
for (int i=0;i<5;i++)
{
System.out.println (i);
}
}
}
While loop statement format: while (conditional expression) {loop body statement}
The specific code is as follows:
public class Demo10
{
public static void Main (String[]args)
{
int i=0;
while (i)
{
System.out.println (i);
i++;
}
}
}
Do-while Loop statement Format do
{
loop body statement;
}
while (conditional expression statement);
The specific code is as follows:
public class Demo11
{
public static void Main (String[]args)
{
int i=0;
Do
{
System.out.println (i)
i++;
}
while (I>5);
}
}
3. Mastering the Branch structure ()
4. Mastering the use of the IF statement
if (conditional statement) {... }
if (conditional statement) {... }else{... }
if (conditional statement) {... }else if (conditional statement) {... }
if (conditional statement) {... }else if (conditional statement) {... }else{... }
The specific code is as follows:
public class Demo1
{
public static void Main (String[]args)
{
int i=3;
if (i>4)
{
System.out.println (i);
}
}
}
5. Mastering the use of switch statements
Switch
Switch (1)
{
Case 0: statement block 1;break;
Case 1: statement block 2;
Case 2: statement block 3;
Case 3: statement block 4;break;
······
case N; statement block N; break;
Default: statement block N+1;break;
}
The specific code is as follows:
public class Demo9
{
public static void Main (String [] args)
{
int i=3; Used to denote the first quarter.
Switch (i)
{
Case 1:
System.out.println ("This is the first quarter");
Break
Case 2:
System.out.println ("This is the second quarter");
Break
Case 3:
System.out.println ("This is the third quarter");
Break
Case 4:
System.out.println ("This is the fourth quarter");
Break
Default
SYSTEM.OUT.PRINTLN ("incorrect output");
}
}
}
Conditional Statement-switch statement about rules
1 The return value of an expression must be one of the following types:
int byte char short
2 The value of the case sub-statement must be a constant, and the values in all case sub-statements should be different
3 The default statement is optional
4 The break statement is used to jump out of a switch statement block after executing a case branch
Branching statements for the Java language Branch statement