a+aa+aaa+aaa+......AAAAAaAaaaaa....a是任意一个数,求最后结果中有多少个一,,,,,,怎么做啊
应该加个什么东西啊
public class TestSum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入基数(0——9)!");
int num = sc.nextInt();
System.out.println("请输入位数!");
int n = sc.nextInt();
int sum = 0;
int result = 0;
int temp = num;
if(num<0||num>9||n<=0) {
System.out.println("输入错误!");
}else {
for(int i=1;i<n;i++) {
temp = temp*10 + num;
sum = sum + temp;
}
result = sum + num;
System.out.println(result);
}
}