题解 | #等差数列#
等差数列
http://www.nowcoder.com/practice/f792cb014ed0474fb8f53389e7d9c07f
此题过于为简单题,读代码即可读懂。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()) {
int n = sc.nextInt();
int count = -1; // 记录当前的值
int sum = 0; // 记录总和
for(int i=0; i<n; i++) {
count += 3;
sum += count;
}
System.out.println(sum);
}
}
}