目录
题目描述
输入n和a,求a+aa+aaa+…aa…a(n个a),如当n=3,a=2时,2+22+222的结果为246
输入
包含两个整数,n和a,含义如上述,你可以假定n和a都是小于10的非负整数
输出
输出前n项和,单独占一行
样例输入 Copy
3 2
样例输出 Copy
246
code
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), a = sc.nextInt(), b = a;
int sum = 0;
for (int i = 0; i < n; i ++) {
sum += a;
a = a * 10 + b;
}
System.out.printf("%d", sum);
}
}
标签:1052,Java,int,样例,sum,ZZULIOJ,sc,Copy,输入
From: https://blog.csdn.net/m0_64604482/article/details/137571239