一、题目需求
让while(true)循环执行5次就结束
方法 :在while循环上面定义一个 int i=0 然后刚进循环给个++i 循环末尾给个if判断即可
二、代码示例
/*
* Copyright (c) 2020, 2023, webrx.cn All rights reserved.
*
*/
package huang4;
public class A1 {
public static void main(String[] args) {
int i = 0;
while (true) {
++i;
System.out.println("helloword");
if (i == 5) {
break;
}
}
}
}
三、运行结果展示