标签:== mic 结束 put lazy inf alt png out
简单来说就是while如果不满足一次都不执行,do while 不满足至少执行一次
格式:
do{
要执行的语句;
}while(判断条件);
package com.wenjian.struct;
import java.sql.SQLOutput;
public class DoWhileDemo01 {
public static void main(String[] args) {
int i = 0;
int sum = 0;
do {
sum = sum + i;
i++;
} while (i <= 100);
System.out.println(sum);
}
}
输出:
5050
进程已结束,退出代码 0
package com.wenjian.struct;
public class DoWhileDemo02 {
public static void main(String[] args) {
int a = 0;
while (a < 0) {
System.out.println(a);
a++;
}
System.out.println("=========");
do {
System.out.println(a);
a++;
} while (a<0);
}
}
输出:
=========
0
进程已结束,退出代码 0
标签:== mic 结束 put lazy inf alt png out
原文地址:https://www.cnblogs.com/function123/p/13338786.html