Hello everyone) There is a matrix of 100x100. It is necessary to sum each column of the matrix, divide the sum of each column by the number of elements in it and put the result into a one-dimensional array. With the summation of the columns and the number of elements, I kind of figured out)

public class Etalon { public static void etalonMatrix(int [][] convertToMatrix) { int [][] mas = convertToMatrix; int s = 0; int k = 0; for (int i = 0; i < convertToMatrix[0].length; i++){ s = 0; k=0; for (int j = 0; j < convertToMatrix.length; j++){ s = s + mas [j][i]; k++; } /** System.out.println(s); System.out.println(" "); System.out.println(k);*/ } } } 

And I can't transfer all this to a one-dimensional array (

  • And what is the difficulty? Create an array and in a cycle of I after the calculation assigns to it the result. - Smithson

1 answer 1

 public class Etalon { public static void etalonMatrix(int [][] convertToMatrix) { int [][] mas = convertToMatrix; int [] result = new int[convertToMatrix.length]; int s = 0; int k = 0; for (int i = 0; i < convertToMatrix[0].length; i++){ s = 0; k=0; for (int j = 0; j < convertToMatrix.length; j++){ s = s + mas [j][i]; k++; result[j] = s; } } for(int p = 0; p < result.length; p++){ System.out.print(result[p]+" "); } } } 

Try this, you may have made a mistake by inattention, but the essence is as follows.

  • one
    Thank you very much everything is correct))) you only need to sort through the array by i. - Dasha Novikova