JAva毎日小アルゴリズム(8)


/*【  8】
  : s=a+aa+aaa+aaaa+aa...a  ,  a     。  2+22+222+2222+22222(    5    ),          。  */
package test;
import java.util.Scanner;
public class test {
     public static int sum(int number, int input) {
         int result = 0;
         int tem = number;
         for(int i = 0; i < input; i++)
         {
             for(int j = i; j > 0; j--)
             {
                 tem = tem + (int) Math.pow(10, j)*number;
             }
             result += tem;
             tem = number;
         }
         return result;
     }
          
      
 public static void main(String[] args) {
     long a = System.currentTimeMillis();
     int number = 2;
     Scanner s = new Scanner(System.in);
     System.out.println("Please input the number count:");
     int input = s.nextInt();
     int sum = sum(number, input);
     System.out.println("sum is "+sum);
     System.out.println(System.currentTimeMillis() - a);
 }
}