等差数列求和公式:(a1 + an) * n / 2
an = a1 + (n - 1) * d;
private static void calc(int n) {
if(n <= 0){
System.out.println("非法输入");
return;
}
int d = 3;
int a1 = 2;
int an = a1 + (n - 1) * d;
int sum = (a1 + an) * n / 2;
System.out.println(sum);
}
等差数列求和公式:(a1 + an) * n / 2
an = a1 + (n - 1) * d;
private static void calc(int n) {
if(n <= 0){
System.out.println("非法输入");
return;
}
int d = 3;
int a1 = 2;
int an = a1 + (n - 1) * d;
int sum = (a1 + an) * n / 2;
System.out.println(sum);
}