题解 | #等差数列#
等差数列
https://www.nowcoder.com/practice/f792cb014ed0474fb8f53389e7d9c07f
import java.util.Scanner;
import java.util.Stack;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int a =scan.nextInt();
int b = 2;
Stack stack = new Stack<Integer>();
stack.push(b);
for (int i=1;i<a;i++){
b=b+3;
stack.push(b);
}
Integer num = 0;
while(!stack.isEmpty()){
num +=(Integer)stack.pop();
}
System.out.println(num);
}
}