public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (true) {
int a = scan.nextInt();
int n = scan.nextInt();
int Sn = add(a, n);
System.out.println(Sn);
}
}
public static int add(int a,int n){
int sum = 0;
int Sn = 0;
for (int i = 1; i <= n; i++) {
sum = sum * 10 + a;
Sn = Sn + sum;
}
return Sn;}
Java n由键盘输入,求Sn=a+aa+aaa+aaaa+...+aa...a(n个a)
最新推荐文章于 2023-01-20 15:00:21 发布