一.while
package java;
public class java {
public static void main(String[] arge) {
int i = 0;
int sum = 0;
while (i<100){
sum=sum+i;
i+=2;
}
System.out.println("从0到100的偶数之和为:"+sum);
}
}
二.do—while
public static void main(String[] args) {
int i = 0;
int sum = 0;
do {
i++;
if (i%2==0) {
sum=sum+i;
}
} while (i<=100);
System.out.println(sum);
}
}
三.for
public static void main(String[] args) {
int sum=0;
for (int i = 0; i <=100; i++) {
if (i%2==0) {
sum=sum+i;
}
}
System.out.println(+sum);
}
}