public class SumDemo {
public static void main(String[] args) {
int sum=0;
Scanner reader=new Scanner(System.in);
int a=reader.nextInt();//要相加的值
int n=reader.nextInt();//相加的次数
int t=a;
for(int i=0;i<n;i++){
sum=sum+t;
t=t*10+a;
}
System.out.println("和为:"+sum);
}
} |
|