4、计算1~100之间所有奇数的和。```
package com;
public class sum {
public static void main(String[] args) {
// TODO Auto-generated method stub
int sum=0,i;
for(i=1;i<=100l;i++)
if(i%2==1)
sum+=i;
System.out.println("100以内奇数和=" + sum);
}
}
4、计算1~100之间所有奇数的和。```
package com;
public class sum {
public static void main(String[] args) {
// TODO Auto-generated method stub
int sum=0,i;
for(i=1;i<=100l;i++)
if(i%2==1)
sum+=i;
System.out.println("100以内奇数和=" + sum);
}
}