While 的基础结构
public class WhileDemo01 {
public static void main(String[] args) {
//输出1-100
int i = 0;
while (i < 100){
i++;
System.out.println(i);
}
}
}
public class WhileDemo02 {
public static void main(String[] args) {
//计算1+2+3+...+100=? while 先判断再循环
int i = 0;
int sum = 0;
while (i<100){
i++;
sum += i;
}
System.out.println("结果为:" + sum);
//DO while 先循环一次,再进行判断
int a = 0;
int total = 0;
do {
a++;
total += a;
}while (a < 100);
System.out.println("结果为:" + total);
}
}
标签:int,基础,while,While,static,100,public,结构
From: https://www.cnblogs.com/GXEndeavor/p/18668215