当前位置: 首页 > 工具软件 > nnn > 使用案例 >

求 n+nn+nnn+nnnn+........的和(java写法)

游安康
2023-12-01

求 n+nn+nnn+nnnn+…的和(java写法)

public class Work {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入要计算的数");
		int n = sc.nextInt();
		System.out.println("请输入要计算的个数");
		int s = sc.nextInt();
		int num = 0;
		int n1 = n;
		for (int i = 1; i <= s; i++) {
			num += n1;
			n1 = n1 * 10 + n;
			System.out.println(n1);
		}
		System.out.println("结果为" + num);
	}

}
 类似资料: