1.while用法
package come.one;
public class One15 {
public static void main(String[] args) {
int sum= 0;
int i= 0;
while(i<=100) {
sum += i;
i += 2;
}
System.out.println("100以内的偶数之和为:"+sum);
}
}
2.do-while用法
package come.one;
public class One16 {
public static void main(String[] args) {
int sum= 0;
int i= 0;
do {
sum +=i;
i += 2;
}while(i<=100);
System.out.println("100以内的偶数之和为:"+sum);
}
}
3.for用法
package come.one;
public class One17 {
public static void main(String[] args) {
int sum = 0;
for(int i =0;i <= 100;i += 2){
sum += i;
}
System.out.println("100以内的偶数之和为:"+sum);
}
}
输出结果