What is JAVA structured programming
This article focuses on "what is JAVA structured programming". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is JAVA structured programming"?
Catalogue
1. What is structured programming?
two。 Why use structured programming?
3. Three major structures
a. Cyclic structure
One line of code:
b. Branching structure
c. Repetitive structure
4. Function (called method in JAVA)
1. What is structured programming?
Only three structures are used in programming
You cannot use the Goto statement
In 1972, an American scientist published a paper proving that all program flows need only three major structures to complete.
two。 Why use structured programming?
Divide the code into blocks of code
Greatly improves the readability of the code
3. Three major structures A. Cyclic structure
Single thread (an execution sequence)
The code always executes the previous line and then the next line
In sequential structures, beware of empty statements that are accidentally generated.
/ / empty statement example: public class BanchTest {public static void main (String [] args) {int i; for (iDiscriminant 18) {/ / consistent with discriminant expression executor System.out.println ("adult");} else {/ / non-compound discriminant expression executor System.out.println ("minor");}
Multi-branch structure
a. Multiple-choice structure (multiple branch structures, only one is executed)
Using else if is more efficient than meeting the conditions of a single branch, and all branches will execute only one at the same time.
Package com.kfm.leiyawen.Test0831;public class BanchTest {public static void main (String [] args) {test1 ();} private static void test1 () {int age = 37; if (age)