笔记:Whlie循环/Do Whlie循环
作者:互联网
whlie循环
public class WhlieDemo03 {
public static void main(String[] args) {
int i = 0; //初始化条件
int sum = 0;
while (i<=100){ //条件判断
sum += i; //循环体
i++; //迭代
}
System.out.println("whlie循环总和:"+sum);
}
}
do whlie循环
public class DoWhlieDemo01 {
public static void main(String[] args) {
int i = 0;
int sum = 0;
//循环体先执行一次,在进行判断
//所以dowhile循环至少执行一次
do {
sum += i;
i++;
}while (i<=100);
}
}
标签:Do,int,sum,循环,static,Whlie,public 来源: https://www.cnblogs.com/seawavelin/p/15119050.html