当前位置:网站首页>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 
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 .
边栏推荐
- i.MX - RT1052 SPI和 I2C接口
- Methods commonly used in uniapp (part) - timestamp problem and rich text parsing image problem
- Tensorflower uses the specified GPU and GPU video memory
- channels详细使用说明
- 网页加载时waiting(TTFB)时间过长的问题解决
- Record the errors encountered in the pytorch training model once
- Related codes of findpanel
- 五大(七大)原则-系统学习三
- Redis maximum memory elimination strategy
- 程序三大结构-系统学习一
猜你喜欢

一篇文章带你搞懂什么是DevOps?

3D Slicer将分割结果保存

2-zabbix automatically add hosts using autodiscover

i. MX - rt1052 clock and phase locked loop (PLL) analysis

i. MX - rt1052 boot start

简单工厂VS工厂方法&手写自动化工厂——系统学习六

巨头局终战:即时零售

i. MX - rt1052 input / output (GPIO)

Schéma technique du système de surveillance de l'environnement de la salle de distribution

Nanjing University static program analyses -- intermediate representation learning notes
随机推荐
创建型模式 - 单例模式
3D Slicer导入标签与查看标签
架构师培养计划-无限思维——变量
一文掌握SQLite3基本用法
Why are there only 13 root domain name servers in the world
最新远程部署运维工具汇总
The wechat authorization login window will pop up automatically
typescript localStorage 封装
Embedded struct and embedded interface
Version number naming convention
i. MX - rt1052 boot start
i. MX - rt1052 pulse width modulation (PWM)
i.MX - RT1052 BOOT启动
这3个后生,比马化腾、张一鸣还狠
Musk's "good friend" impacts the largest IPO of Hong Kong stocks in 2022
CPU、MPU、MCU、SoC、MCM介绍
EasyUI-input取/赋值
[100 unity practical skills] | make the skills or equipment follow the character and rotate continuously in the game
PWM (pulse width modulation) of STM32 notes
~~~~配置