Weighted sum of digits

Back to General discussions forum

Sabina_Belyaeva     2016-12-06 16:35:15

Hello, my code doesn't work. If you find a mistake, please let me know. public class WeightedSumOfDigits {

public static void main(String[] args){ Scanner scan = new Scanner(System.in); int[] array1 = new int[300]; int output = scan.nextInt(); int hr =0; int sum =0; int pussy =0; for(int i= 0; i<output; i++){ array1[i] = scan.nextInt();

 Vizov lol = new Vizov();
 lol.vizov(array1[i]);
 while(array1[i] != 0){
     pussy = array1[i]%10;
     for (int k =0; k<lol.x;k++){
     sum += (lol.x-k)*pussy;
      hr= array1[i]/10; 
 }
     System.out.print(sum);
 }

}

} }

public class Vizov { public static int[] size = {9, 99, 999, 9999,99999,999999,9999999,99999999,999999999,Integer.MAX_VALUE}; public static int x =0; public void vizov(int n){ for (int j =0; ; j++){ if( n >= size[j]){ x++;

 }else if(n<= size[j]){
     x++;

     break;
 }

} }

}

Please login and solve 5 problems to be able to post at forum