当前位置:网站首页>程序三大结构-系统学习一
程序三大结构-系统学习一
2022-06-21 12:07:00 【创业之路&下一个五年】
一、背景介绍
1.经过高人指路,略有通透;潜心苦学,终有所成。
2.自此将自己的感受进行记录;所谓世间万物都可以通过公理+逻辑进行推理出来,那么程序中的公理是什么呢?对了,您猜对了,就是我下面要介绍的三大结构。
3.计算机科学家Corrado Bohm和Giuseppe Jacopini证明,使用顺序(sequencing),选择(alternation)和循环(iteration)这三种结构就足以表达所有程序的本质(《编程导论(Java)·3.1.1 三种结构、Java语句》 严千钧 著.编程导论(Java).北京:清华大学出版社)。
二、学习思路
1.绘制图
2.查阅资料、并完善图
3.编写代码
4.代码和图对比理解,图中每一个箭头每一个拐角在代码中的对应关系
5.过程中提出问题,用示例和书中的描述来解答问题
三、学习过程
1.下面为三大结构图
2.下面为三大结构对应的代码
package com.a1threeStructures;
/** * 功能描述:顺序结构 * * @Author:makang * @Date: 2021/4/16 9:30 */
public class a1_sequencing {
public static void main(String[] args) {
//以下在眼睛可见的过程中是执行3行语句
//如果加上汇编语言可就不是三句了,
String who = "我";
String what = "是一个顺序结构";
System.out.println(who+what);
}
}
package com.a1threeStructures;
/** * 功能描述:选择结构 * * @Author:makang * @Date: 2021/4/16 9:30 */
public class a2_alternation {
public static void main(String[] args) {
//if else实现
System.out.println("一、小马开始利用if else 来实现三大结构中选择结构的作用与意义");
//1.单选
ifSingleChoice();
//2.双选
ifDoubleChoice();
//3.多选
ifMultipleChoice();
//4.嵌套判断
ifNestingJudgment();
// switch case的示例
System.out.println();
System.out.println("二、小马开始利用switch case来实现三大结构中选择结构的作用与意义");
//switch 单选
switchSingleChoice();
//switch 双选
switchDoubleChoice();
//switch 多选
switchMultipleChoice();
System.out.println("小马开始利用switch case来实现三大结构中选择结构的作用与意义——结束");
}
/** * if单选 *@param *@return */
public static void ifSingleChoice(){
String name = "小马";
if(name== "小马")
//交汇点(圆圈)
{
System.out.println("1."+name+",实现了if else中的单选结构");
}
//18行
System.out.println("小马写的程序继续跑。。。。");
}
/** * 方法描述:if双选 *@param *@return */
public static void ifDoubleChoice(){
String name = "小马";
if(name == "小马"){
System.out.println("2."+name+",实现了if else 中的双选结构true情况");
}else{
System.out.println("2."+name+",实现了if else 中的双选结构false情况");
}
System.out.println("小马写的程序继续跑。。。。");
}
/** * 方法描述:if多选 *@param *@return */
public static void ifMultipleChoice(){
String name = "小马";
if(name == "小马"){
System.out.println("3."+name+",实现了if else 中的多选结构;当名称等于小马的时候");
}else if(name == "小张"){
System.out.println("3."+name+",实现了if else 中的多选结构;当名称等于小张的时候");
}else{
System.out.println("3."+name+",实现了if else 中的多选结构;当名称不是小马、小张的时候");
}
System.out.println("小马利用if else 来实现三大结构中选择结构的作用与意义;结束");
}
/** * 方法描述:if嵌套判断 *@param *@return */
public static void ifNestingJudgment(){
String name = "小马";
if(name.contains("小")){
System.out.println("4."+name+",进入了第一层判断,"+name+"的名字中包含小");
if(name.contains("马")){
System.out.println("4."+name+",进入了第二层判断,"+name+"的名字中包含马");
}else{
System.out.println("4."+name+",进入了第二层判断,"+name+"的名字中不包含马");
}
}else{
System.out.println("4."+name+",进入了第一层判断,"+name+"的名字中不包含小");
}
}
/** * switch单选 *@param *@return */
public static void switchSingleChoice(){
String name = "小马";
System.out.println("小马写的程序继续跑。。。。");
switch(name){
case "小马" :
System.out.println("1."+name+",实现了switch case中的单选结构;当名称等于小马的时候");
break;
}
System.out.println("小马写的程序继续跑。。。。");
}
/** * 方法描述:switch双选 *@param *@return */
public static void switchDoubleChoice(){
String name = "小马";
switch(name){
case "小马" :
System.out.println("2."+name+",实现了switch case中的双选结构;当名称等于小马的时候");
break;
case "小张":
System.out.println("2."+name+",实现了switch case中的双选结构;当名称等于小马的时候");
break;
}
System.out.println("小马写的程序继续跑。。。。");
}
/** * 方法描述:switch多选 *@param *@return */
public static void switchMultipleChoice(){
String name = "小马";
switch(name){
case "小马" :
System.out.println("3."+name+",实现了switch case中的多选结构;当名称等于小马的时候");
break;
case "小张":
System.out.println("3."+name+",实现了switch case中的多选结构;当名称等于小张的时候");
break;
default:
System.out.println("3."+name+",实现了switch case中的多选结构;当名称等于小马&小张的时候");
}
}
}
package com.a1threeStructures;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
/** * 功能描述:循环结构 * * @Author:makang * @Date: 2021/4/16 9:30 */
public class a3_iteration {
public static void main(String[] args) {
//1.for 当
forType();
//2.foreach 当
System.out.println();
foreachType();
//3.while 当
System.out.println();
whileType();
//4.do while 直到
System.out.println();
doWhileType();
//5.迭代器 当
System.out.println();
iteratorType();
}
/** * 方法描述:for循环 *@param *@return */
public static void forType(){
String name = "小马";
System.out.println("一、"+name+",开始用for来实现三大结构中的循环结构了");
for (int i = 0; i < 3; i++) {
System.out.println(name+",循环了第"+i+"次");
}
}
/** * 方法描述:foreach循环 *@param *@return */
public static void foreachType(){
String name = "小马";
System.out.println("二、"+name+",开始用foreach来实现三大结构中的循环结构了");
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
for (int i:list) {
System.out.println(name+",循环的内容为:"+i);
}
}
/** * 方法描述:while循环 *@param *@return */
public static void whileType(){
String name = "小马";
System.out.println("三、"+name+",开始用while来实现三大结构中的循环结构了");
int i = 0;
while (i < 3){
System.out.println(name+",循环次数为第"+i+"次");
i++;
}
}
/** * 方法描述:do while 循环 *@param *@return */
public static void doWhileType(){
String name = "小马";
System.out.println("四、"+name+",开始用do while来实现三大结构中的循环结构了");
int j = 0;
do {
System.out.println(name+",循环次数为第"+j+"次");
j++;
}while (j < 3);
}
/** * 方法描述:迭代器循环 *@param *@return */
public static void iteratorType(){
String name = "小马";
System.out.println("五、"+name+",开始用Iterator来实现三大结构中的循环结构了");
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+",循环次数中的值为:"+integerIterator.next());
integerIterator.remove();
}
}
}
3.下面为学习过程中产生的问题
顺序的作用与意义?
三大结构的边界?
四、学习总结
1.三大结构在编程中的意义更加明确了
2.编程从三大结构考虑问题,这样的思考方式、学习方式也有了更加深刻的认识与理解
五、升华
1.代码如人生:
人生中又何尝不是顺序的执行,遇到路口进行选择,选择完之后又继续无限的循环进行。
2.然而在选择的时候我们可以详细考虑清楚,一旦选择了之后就要坚定不移的执行下去,终能达到自己所期望的结果。
3.发现事情的本质,编程是如此简单;通过知识的学习,建立自信人生。
边栏推荐
- i.MX - RT1052 BOOT启动
- [cloud native | Devops] Jenkins installation and actual combat (II)
- Quantitative research on heterogeneous communities 4 rate of change with bands
- 记录一次pytorch训练模型遇到的报错
- The final battle of the giant: instant retailing
- Transaction
- 2. 引用
- 2-zabbix automatically add hosts using autodiscover
- Snow Ice City (blackened)
- 3. 函数提高
猜你喜欢

CPU、MPU、MCU、SoC、MCM介绍

uniapp中常用到的方法(部分) - 时间戳问题及富文本解析图片问题

3D Slicer将分割结果保存

Chapter VIII web project testing

Quantitative research on heterogeneous communities 4 rate of change with bands

Summary of UART problems in stm32cubemx

RPC(远程过程调用协议)

STM32開發之 VS Code + gcc環境編譯

i. MX - rt1052 SPI and I2C interfaces

浅论OCA\UV-OCA LOCA\SLOCA 四种全贴合工艺
随机推荐
MySQL-DQL
What are the precautions for PCB design?
创建型模式 - 单例模式
STM32笔记之 SWJ(JTAG-DP和 SW-DP)
Use huggingface to quickly load pre training models and datasets in the moment pool cloud
Musk's "good friend" impacts the largest IPO of Hong Kong stocks in 2022
理解RESTful架构
i. MX - rt1052 SPI and I2C interfaces
为什么世界上只有13个根域名服务器
Architect training plan - infinite thinking - variables
i.MX - RT1052时钟及锁相环(PLL)分析
Centos7 升级MySQL5.6.40至企业版5.6.49
Matrial3d parameter analysis
2022年138套数学分析高等代数考研真题参考解答勘误
PWM (pulse width modulation) of STM32 notes
uniapp-微信小程序获取定位授权
RPC(远程过程调用协议)
MySQL 5.6.49 enterprise version setting password complexity policy
【云原生 | Devops篇】Jenkins安装与实战(二)
异质化社群量化研究4丨RATE OF CHANGE WITH BANDS