package ytr250813;
import java.util.Scanner; // 导入Scanner类,用于获取键盘输入
public class SpecialSequenceSum {
public static void main(String[] args) {
// 创建Scanner对象用于接收用户输入
Scanner scanner = new Scanner(System.in);
// 获取用户输入的数字a
System.out.print("请输入一个数字(0-9):");
int a = scanner.nextInt();
// 获取用户输入的项数n
System.out.print("请输入要相加的项数:");
int n = scanner.nextInt();
// 关闭Scanner对象
scanner.close();
// 初始化当前项的值和总和
long currentTerm = 0; // 当前项的值
long totalSum = 0; // 所有项的总和
// 打印计算过程的标题
System.out.print("计算过程:");
// 循环计算每一项的值并累加
for (int i = 1; i <= n; i++) {
// 计算当前项:前一项的值乘以10再加上a
currentTerm = currentTerm * 10 + a;
// 累加到总和中
totalSum += currentTerm;
// 打印当前项,如果是最后一项则不打印加号
System.out.print(currentTerm);
if (i < n) {
System.out.print(" + ");
}
}
// 打印最终结果
System.out.println(" = " + totalSum);
}
}