What are the logical structure patterns in Java
In this article, the editor introduces in detail "what are the logical structure patterns in Java", with detailed content, clear steps and proper handling of details. I hope that this article "what are the logical structure patterns in Java" can help you solve your doubts? let's follow the editor's ideas to learn new knowledge.
Sequential structure
As the name implies, the sequential structure is executed in the order of the code, which is needless to say.
Branching structure
The branch structure can be subdivided into two:
If... Else... I believe we both know these two words. Translating them into Chinese is what we usually call "if". Just... So how do you use it in Java:
①: if else:
Its basic grammatical structure is as follows:
If (judgment condition) {
Statement 1
} else {
Statement 2
When the judgment condition is true, execute statement 1, otherwise execute statement 2
Example:
Import java.util.*;public class TestDemo13 {public static void main (String [] args) {Scanner scanner = new Scanner (System.in); int n = scanner.nextInt (); if (n > = 5) {System.out.println ("hello");} else {System.out.println ("hehe");}
The meaning of this code is that we enter a number. If the number is greater than or equal to 5 and meets the if condition, execute the statement in our if. If it is not satisfied, execute the following statement.
Note: the parentheses after if can only be Boolean expressions, not mathematical expressions, such as if (5