Skip to content

Commit

Permalink
✅ 更新JavaSE文档
Browse files Browse the repository at this point in the history
  • Loading branch information
SakuraMuxia committed Feb 19, 2025
1 parent b2ce4f1 commit d0bd1f2
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions docs/back-end/001-JavaSE/004-流程控制.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ public class TestSwitch3 {
## while循环

先判断,后执行

```java
计数器初始化;

Expand Down Expand Up @@ -613,6 +615,8 @@ public class TestCheckStudy {

## do-while循环

先执行,后判断

```java
计数器初始化;
do {
Expand Down Expand Up @@ -722,15 +726,14 @@ for(计数器初始化;循环条件;计数器变化){

```ts
循环次数确定的情况 使用for循环 更加简洁

注意for循环的执行顺序:
注意for循环的执行顺序:
第一轮:
1.执行计数器初始化 并且只执行一次
2.判断条件
3.执行循环体
4.执行计数器变化
1.执行计数器初始化 并且只执行一次
2.判断条件
3.执行循环体
4.执行计数器变化
后续轮:
直接从第2步开始执行
直接从第2步开始执行
```

**示例1**
Expand Down Expand Up @@ -1195,5 +1198,27 @@ public class PrintParallelogram {
}
}
}

```

打印 三角形

```java
public class TestWhile {
public static void main(String[] args) {
for(int i=1;i <=5;i++){ // 外层循环 控制行数
// 左半部分
for(int j = 5; j >= i;j--){
System.out.print(" ");
}
// 右半部分
for(int j = 1;j <= (2 * i -1);j++){
System.out.print("*");
}
// 换行
System.out.println();
}
}
}
```

0 comments on commit d0bd1f2

Please sign in to comment.