从0~50,输出它的偶数和
for(int sum=0,num=2;num<50;sum+=num,num+=2){
System.out.println("50以内的偶数和为:“+sum);
}
public class Test
{
public static void main(String[] args){
int sum=0;
int num;
for(num=2;num<=50;)
{
sum=sum+num;
num=num+2;
}
System.out.println(sum);
}
}
for(int sum=0,num=0;num<=50;num=num+2,sum=sum+num){
System.out.println("50以内的偶数和为:"+sum);