解题思路:
程序先用Scanner读入a1,a2和n三个整数,然后计算出等差数列的公差d。接着,利用等差数列的通项公式a_n = a_1 + (n-1)d,计算出第n项的值,并输出结果。注意事项:
参考代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a1 = input.nextInt();
int a2 = input.nextInt();
int n = input.nextInt();
int d = a2 - a1; // 公差
int r = a1 + (n - 1) * d; // 等差数列公式
System.out.println(r);
}
}
0.0分
1 人评分