当前位置:网站首页>Three structures of program - system learning I

Three structures of program - system learning I

2022-06-21 12:26:00 The road to entrepreneurship & the next five years

One 、 Background introduction

1. Pass the expert to show you the way , Slightly transparent ; Study hard , There's always a way .
2. Since then, I have recorded my feelings ; All things in the world can pass the axiom + Logic to reason out , So what are the axioms in the program ? by the way , You're right , These are the three structures I will introduce below .
3. Computer scientists Corrado Bohm and Giuseppe Jacopini prove , Order of use (sequencing), choice (alternation) And circulation (iteration) These three structures are sufficient to express the essence of all programs (《 Introduction to programming (Java)·3.1.1 Three structures 、Java sentence 》 Yanqianjun Writing . Introduction to programming (Java). Beijing : tsinghua university press ).

Two 、 Learning ideas

1. Mapping
2. Access to information 、 And improve the picture
3. Write code
4. Compare the code with the diagram , The corresponding relationship between each arrow and each corner in the code
5. Ask questions in the process , Answer questions with examples and descriptions in the book

3、 ... and 、 The learning process

1. The following are three structural diagrams
 Insert picture description here

2. The following is the code corresponding to the three structures

package com.a1threeStructures;

/** *  Function description : Sequential structure  * * @Author:makang * @Date: 2021/4/16 9:30 */
public class a1_sequencing {
    

    public static void main(String[] args) {
    

        // The following is performed while the eye is visible 3 Line statement 
        // If you add assembly language, it will not be three sentences ,
        String who = " I ";
        String what = " It's a sequential structure ";
        System.out.println(who+what);

    }
}

package com.a1threeStructures;

/** *  Function description : Selection structure  * * @Author:makang * @Date: 2021/4/16 9:30 */
public class a2_alternation {
    

    public static void main(String[] args) {
    
        //if else Realization 
        System.out.println(" One 、 The pony began to use if else  To realize the function and significance of selecting structure among the three structures ");
        //1. The radio 
        ifSingleChoice();
        //2. Double choice 
        ifDoubleChoice();
        //3. multi-select 
        ifMultipleChoice();
        //4. Nested judgments 
        ifNestingJudgment();

        // switch case An example of 
        System.out.println();
        System.out.println(" Two 、 The pony began to use switch case To realize the function and significance of selecting structure among the three structures ");
        //switch  The radio 
        switchSingleChoice();
        //switch  Double choice 
        switchDoubleChoice();
        //switch  multi-select 
        switchMultipleChoice();

        System.out.println(" The pony began to use switch case To realize the function and significance of selecting structure among the three structures —— end ");

    }

    /** * if The radio  *@param *@return */
    public static void ifSingleChoice(){
    
        String name = " The pony ";
        if(name== " The pony ")
        // intersection ( circle )
        {
    
            System.out.println("1."+name+", Realized if else Single choice structure in ");
        }
        //18 That's ok 
        System.out.println(" The program written by pony continues to run ....");
    }

    /** *  Methods described :if Double choice  *@param *@return */
    public static void ifDoubleChoice(){
    
        String name = " The pony ";
        if(name == " The pony "){
    
            System.out.println("2."+name+", Realized if else  Double choice structure in true situation ");
        }else{
    
            System.out.println("2."+name+", Realized if else  Double choice structure in false situation ");
        }
        System.out.println(" The program written by pony continues to run ....");
    }

    /** *  Methods described :if multi-select  *@param *@return */
    public static void ifMultipleChoice(){
    
        String name = " The pony ";
        if(name == " The pony "){
    
            System.out.println("3."+name+", Realized if else  Multi select structure in ; When the name equals the pony ");
        }else if(name == " Xiao Zhang "){
    
            System.out.println("3."+name+", Realized if else  Multi select structure in ; When the name equals Xiao Zhang ");
        }else{
    
            System.out.println("3."+name+", Realized if else  Multi select structure in ; When the name is not pony 、 When Xiao Zhang ");
        }
        System.out.println(" Ponies use if else  To realize the function and significance of selecting structure among the three structures ; end ");
    }

    /** *  Methods described :if Nested judgments  *@param *@return */
    public static void ifNestingJudgment(){
    
        String name = " The pony ";
        if(name.contains(" Small ")){
    
            System.out.println("4."+name+", Entered the first level of judgment ,"+name+" The name of contains small ");
            if(name.contains(" Horse ")){
    
                System.out.println("4."+name+", Entered the second level of judgment ,"+name+" The name of contains the horse ");
            }else{
    
                System.out.println("4."+name+", Entered the second level of judgment ,"+name+" The name of does not include horses ");
            }
        }else{
    
            System.out.println("4."+name+", Entered the first level of judgment ,"+name+" The name of does not contain small ");
        }
    }

    /** * switch The radio  *@param *@return */
    public static void switchSingleChoice(){
    
        String name = " The pony ";
        System.out.println(" The program written by pony continues to run ....");
        switch(name){
    
            case " The pony " :
                System.out.println("1."+name+", Realized switch case Single choice structure in ; When the name equals the pony ");
                break;
        }
        System.out.println(" The program written by pony continues to run ....");
    }

    /** *  Methods described :switch Double choice  *@param *@return */
    public static void switchDoubleChoice(){
    
        String name = " The pony ";

        switch(name){
    
            case " The pony " :
                System.out.println("2."+name+", Realized switch case Double choice structure in ; When the name equals the pony ");
                break;
            case " Xiao Zhang ":
                System.out.println("2."+name+", Realized switch case Double choice structure in ; When the name equals the pony ");
                break;
        }
        System.out.println(" The program written by pony continues to run ....");
    }

    /** *  Methods described :switch multi-select  *@param *@return */
    public static void switchMultipleChoice(){
    
        String name = " The pony ";
        switch(name){
    
            case " The pony " :
                System.out.println("3."+name+", Realized switch case Multi select structure in ; When the name equals the pony ");
                break;
            case " Xiao Zhang ":
                System.out.println("3."+name+", Realized switch case Multi select structure in ; When the name equals Xiao Zhang ");
                break;
            default:
                System.out.println("3."+name+", Realized switch case Multi select structure in ; When the name equals pony & When Xiao Zhang ");
        }
    }

}

package com.a1threeStructures;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/** *  Function description : Loop structure  * * @Author:makang * @Date: 2021/4/16 9:30 */
public class a3_iteration {
    

    public static void main(String[] args) {
    
        //1.for  When 
        forType();

        //2.foreach  When 
        System.out.println();
        foreachType();

        //3.while  When 
        System.out.println();
        whileType();

        //4.do while  until 
        System.out.println();
        doWhileType();

        //5. iterator   When 
        System.out.println();
        iteratorType();

    }

    /** *  Methods described :for loop  *@param *@return */
    public static void forType(){
    
        String name = " The pony ";
        System.out.println(" One 、"+name+", Start using for To realize the loop structure among the three structures ");

        for (int i = 0; i < 3; i++) {
    
            System.out.println(name+", Cycle the second "+i+" Time ");
        }
    }

    /** *  Methods described :foreach loop  *@param *@return */
    public static void foreachType(){
    
        String name = " The pony ";
        System.out.println(" Two 、"+name+", Start using foreach To realize the loop structure among the three structures ");
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        for (int i:list) {
    
            System.out.println(name+", The contents of the loop are :"+i);
        }
    }

    /** *  Methods described :while loop  *@param *@return */
    public static void whileType(){
    
        String name = " The pony ";
        System.out.println(" 3、 ... and 、"+name+", Start using while To realize the loop structure among the three structures ");
        int i = 0;
        while (i < 3){
    
            System.out.println(name+", The number of cycles is "+i+" Time ");
            i++;
        }
    }

    /** *  Methods described :do while  loop  *@param *@return */
    public static void doWhileType(){
    
        String name = " The pony ";
        System.out.println(" Four 、"+name+", Start using do while To realize the loop structure among the three structures ");
        int j = 0;
        do {
    
            System.out.println(name+", The number of cycles is "+j+" Time ");
            j++;
        }while (j < 3);
    }

    /** *  Methods described : Iterator loops  *@param *@return */
    public static void iteratorType(){
    
        String name = " The pony ";
        System.out.println(" 5、 ... and 、"+name+", Start using Iterator To realize the loop structure among the three structures ");
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);
        Iterator<Integer> integerIterator =list1.iterator();
        while (integerIterator.hasNext()){
    
            System.out.println(name+", The value in the number of cycles is :"+integerIterator.next());
            integerIterator.remove();
        }
    }
}

3. The following are the problems arising from the learning process
The function and significance of order ?
The boundary of the three structures ?

Four 、 Learning summary

1. The meaning of the three structures in programming is more clear
2. Programming considers problems from three major structures , This way of thinking 、 The way of learning also has a deeper understanding

5、 ... and 、 sublimation

1. Code is like life :
Life is also the execution of sequence , Choose at the intersection , After the selection, continue the infinite cycle .
2. However, when choosing, we can consider it in detail , Once you have made your choice, you must unswervingly carry it out , Finally, I can achieve the desired results .
3. Discover the nature of things , Programming is so simple ; Through knowledge learning , Build confidence in life .

原网站

版权声明
本文为[The road to entrepreneurship & the next five years]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211207125283.html