不要自卑,去提升实力
互联网行业谁技术牛谁是爹
如果文章可以带给你能量,那是最好的事!请相信自己
加油o~
Java经典编程习题,初学者可以参考学习
点击下面链接
Java经典编程100例习题汇总
题目描述:
a+aa+aaa+…+aaaaaaaaa=?
解题思路:
其中a为1至9之中的一个数,项数也要可以指定。
代码:
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入a:");
int a = sc.nextInt();
System.out.println("请输入项数:");
int count = sc.nextInt();
int res = 0;
int temp = 0;
for (int i = 0; i < count; i++) {
if (i == 0) {
temp = a;
res += temp;
} else {
temp = temp * 10 + a;
res += temp;
}
}
System.out.println("结果:" + res);
}
}