package lianxi;
import java.util.*;
public class Diejia {
public static void main(String[] args) {
System.out.println("请输入一个基数:");
Scanner jishu = new Scanner(System.in);
int a = jishu.nextInt();
System.out.println("请输入相加的数字个数:");
Scanner geshu = new Scanner(System.in);
int b = geshu.nextInt();
int sum = 0;
String c = "";
for (int j = 0; j < b; j++)
{
//a转为String型
c = c + String.valueOf(a);
//显示基数递增变化
System.out.println(c);
//将String型转回int并求和
sum = sum + new Integer(c);
}
System.out.print("计算结果为 " + sum);
}
}
![](https://images2015.cnblogs.com/blog/917851/201605/917851-20160514141505484-1746540193.png)