OJ find the value of s=a+aa+aaa+aaaa+aa...a

Insert picture description hereYou can convert this formula
2+22+222+2222 = 2 4=20 3+200 2+2000 1

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner scan = new Scanner(System.in);
		int count =0;
		int num = scan.nextInt();
		int flag = scan.nextInt();
		while(true) {
			
			count+=num*flag;				 
			num = num*10;
			flag--;
			if(flag ==0) {
				break;
			}				
		}
		System.out.println(count);
	
}

}

Guess you like

Origin blog.csdn.net/weixin_44822939/article/details/104295703