/*
案列2:求出1-100之间的偶数和
*/
class ForDemo4{
public static void main(String[] args){
int sum = 0;
for(int x = 1;x <= 100;x++){
if(x % 2 == 0){
sum = sum + x;
}
}
System.out.println("1-100之间的偶数和是:"+sum);
System.out.println("------------------------------");
//方式2
int sum1 = 0;
for(int x = 0;x <= 100;x = x+2){
if(x % 2 == 0){
sum1 = sum1 + x;
}
}
System.out.println("1-100之间的偶数和是:"+sum1);
}
}