public class chuanqiuhe {
/**
* @param args
* @return
*/
static /*public static int main(String[] args) {
// TODO Auto-generated method stub
/*int sum=0;
for(int i=1;i<=10;i++)
sum+=i;
System.out.println("Sum from 1 to 10 is"+sum);*/
int Sum(int i1,int i2){
int sum=0;
for(int i=i1;i<=i2;i++)
sum+=i;
return sum;
}
public static void main(String[] args){
System.out.println("Sum from 1 to 10 is"+Sum(1,10));
System.out.println("Sum from 20 to 30 is"+Sum(20,30));
System.out.println("Sum from 35 to 45 is"+Sum(35,45));
}
}
求和2
最新推荐文章于 2023-04-29 21:38:31 发布