Java- Title: seeking s = a + aa + aaa + aaaa + aa ... the value of a, where a is a number. E.g. 2 + 22 + 222 + 2222 + 22222 (in this case the sum total of the number 5), a control keyboard a few numbers together.

package overLay;
import java.util.Scanner;

public class OverLay {

	public static void main(String[] args) {
		
		Scanner input=new Scanner(System.in);

		int num=0,num1=0,num2=0,temp=0;
		
		System.out.println("请输入数字:");
		num1=input.nextInt();
		
		num=num1;
		temp=num1;
		
		System.out.println("请输入项数:");
		num2=input.nextInt();
		
		for (int i = 1; i <num2; i++) {
			
			num=(num*10+num1);
			temp+=num;		
		}
		System.out.println(temp);
	}

}

Published 23 original articles · won praise 2 · Views 1025

Guess you like

Origin blog.csdn.net/weixin_46101839/article/details/104505421