java输出1-100之间的数并求和for+while+do while实现
2021-01-09 08:31
标签:int ring 输出 span void div do while += class java输出1-100之间的数并求和for+while+do while实现 标签:int ring 输出 span void div do while += class 原文地址:https://www.cnblogs.com/Sulater/p/12961951.htmlpublic static void main(String args[]) {
//do while
int sum = 0; //当前之和
int i = 1; //加数
do {
if (i%2==0){
sum+=i;
}
i++;
}while (i);
System.out.println(sum);
}
}public static void main(String args[]) {
//while
int res=0;
int a=1;
while(a) {
if(a%2==0) {
res+=a;
}
a++;
}
System.out.println(res);
}
} public static void main(String []args){
// for
int sum=0;
for(int i=1;i){
if(i%2==0){
sum+=i;
}
}
System.out.println(sum);
}
}
文章标题:java输出1-100之间的数并求和for+while+do while实现
文章链接:http://soscw.com/index.php/essay/41124.html