总结:这道题目。主要是那个位数,需要*10,

while(i<f){

  x+=y;//决定位数上的那个数

sum+=x//求和

  y*10=y;//决定位数

}

package com.b;

import java.util.Scanner;
//输入一个数,如6 s=6+66+666+6666+66666+666666  6位
// 如 5 s=5+55 +555 +5555 +55555 ;  5位
//如  4 s=4 +44 +444 +4444 4 位

public class Ove {

	// b表示位数 b=0;b=2;则a

	// a表数值
	// i表示 a+到b位
	public static void main(String[] args) {
		Scanner c = new Scanner(System.in);
		System.out.println("请输入a的值-----");
		int y = c.nextInt();

		long sum = 0;
		System.out.println("输入相加的项数----");
		int f = c.nextInt();
		int i = 0;
		int b = 0;
		// 5long b=0;
		while (i < f) {
			b += y;
			sum += b;
			y *= 10;
			i++;
			// 相加的项数由输入的数值影响它

		}
		System.out.println(sum);
	}
}

  

相关文章:

  • 2022-12-23
  • 2021-08-20
  • 2021-07-29
  • 2022-12-23
  • 2021-09-20
  • 2022-02-18
  • 2022-12-23
猜你喜欢
  • 2021-10-04
  • 2022-12-23
  • 2021-12-14
  • 2022-02-23
  • 2021-12-17
相关资源
相似解决方案