Skip to content

Commit 0de5002

Browse files
committed
[docs improve] 添加continue、break 和 return的练习题
1 parent f63f4c9 commit 0de5002

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/java/basis/java-basic-questions-01.md

+41
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,47 @@ Java 中的注释有三种:
284284
1. `return;` :直接使用 return 结束方法执行,用于没有返回值函数的方法
285285
2. `return value;` :return 一个特定值,用于有返回值函数的方法
286286
287+
思考一下:下列语句的运行结果是什么?
288+
289+
```java
290+
public static void main(String[] args) {
291+
boolean flag = false;
292+
for (int i = 0; i <= 3; i++) {
293+
if (i == 0) {
294+
System.out.println("0");
295+
} else if (i == 1) {
296+
System.out.println("1");
297+
continue;
298+
} else if (i == 2) {
299+
System.out.println("2");
300+
flag = true;
301+
} else if (i == 3) {
302+
System.out.println("3");
303+
break;
304+
} else if (i == 4) {
305+
System.out.println("4");
306+
}
307+
System.out.println("xixi");
308+
}
309+
if (flag) {
310+
System.out.println("haha");
311+
return;
312+
}
313+
System.out.println("heihei");
314+
}
315+
```
316+
317+
运行结果:
318+
```
319+
0
320+
xixi
321+
1
322+
2
323+
xixi
324+
3
325+
haha
326+
```
327+
287328
### 方法
288329

289330
#### 什么是方法的返回值?方法有哪几种类型?

0 commit comments

Comments
 (0)