A 2+4+6+・・・+1000
解答例
public class A{
public static void main(String args[]){
System.out.print ("2+4+6+・・・+1000=");
System.out.println(f(0));
}
public static int f(int x){
int i;
for(i=2;i<1001;i+=2){
x+=i;
}
return(x);
}
}
B 3+8+13+・・・+503
解答例
public class A{
public static void main(String args[]){
System.out.print ("2+8+13+・・・+503=");
System.out.println(f(0));
}
public static int f(int x){
int i;
for(i=3;i<504;i+=5){
x+=i;
}
return(x);
}
}