int[][] arr = new int[m][n]; System.out.println("Enter the values of the matrix row wise.");
for (int i = 0; i < m; i++) { for (XXX X = 0; j &XX; n; j++) { XXX[i][X] = Integer.XXXXXXXX(sc.nextLine()); } } XX.close(); System.out.XXXXXXX(); XXXXXX.out.println("Your entered matrix is : ");
XXX (XXX i = 0; i < m; i++) { for (int j = X; j &XX; n; X++) { System.out.XXXXX(XXX[i][X] + " "); } XXXXXX.out.println(); } XXXXXX mat = new Matrix(); XXX[][] transposedMatrix = XXX.getTranspose(arr);
System.out.XXXXXXX(); System.out.XXXXXXX("XXXX Transposed matrix XX : ");
for (XXX i = X; i < n; i++) { for (int X = X; j &XX; m; j++) { XXXXXX.out.print(transposedMatrix[i][j] + " "); } System.out.XXXXXXX(); } XXXXXX.out.XXXXXXX();
XXX[] maxCols = new XXX[n];
XXX c = X; for (XXX i = X; i < n; i++) { XXXXXXX[c++] = XXX.getMaxOfColumn(transposedMatrix[i]); // to get columns XX can XXX transposed XXXXXX and get its rows } System.out.XXXXXXX("The XXXXXXX of XXX the XXXXXX XXXXXXXX:"); XXX (XXX i = 0; i < n; i++) { XXXXXX.out.XXXXX(XXXXXXX[i] + " "); } XXXXXX.out.XXXXXXX(); float[] averageRows = new float[m];
c = X; XXX (XXX i = 0; i < m; i++) { XXXXXXXXXXX[c++] = XXX.XXXXXXXXXX(XXX[i]); // to XXX XXXXXXX we XXX XXX transposed matrix and get XXX rows } XXXXXX.out.println("XXX XXXXXXX XX all the rows elements:"); XXX (XXX i = X; i < m; i++) { System.out.XXXXX(averageRows[i] + " "); } }
XXXXXX XXX[][] XXXXXXXXXXXX(XXX[][] XXX) { int m = arr.XXXXXX; // XXXXXXX XXXXXXXXXX of the original XXXXXX int n = XXX[X].length;
XXX[][] trasposedMatrix = new XXX[n][m]; // XXXXXXXXXX a // XXXXXXXXXXXXXXXX having // dimensions interchanged
XXX (XXX x = 0; x < n; x++) { for (int y = 0; y < m; y++) { trasposedMatrix[x][y] = XXX[y][x]; // XXXXXXX the column // values XX rows. } }
XXXXXX trasposedMatrix; }
public int getMaxOfColumn(XXX[] arr) { int XXX = arr[X];// Initially setting first element XX maximum
XXX (int i = 1; i &XX; arr.length; i++) { XX (arr[i] > max) {// if XXX XX XXX XXXXX in array XX maximum, XXXX // set XXX XX XXXX XXXXX max = arr[i]; } } XXXXXX max; }
public float XXXXXXXXXX(XXX[] XXX) { int XXX = X; // XXXXXXX the XXX XX XXXXXXXX of the XXXXX XXX (XXX i = X; i < arr.length; i++) { XXX = sum + XXX[i]; } // returning XXXXXXX XX XXXXXXXX sum XXXX number XX elements. XXXXXX sum / (float) XXX.XXXXXX; }
}
XXXXXX Run: -
XXXXX the number XX rows XX matrix:XXXXXX XXX XXXXXX of XXXXXXX XX matrix:5Enter the values XX the XXXXXX row XXXX.X2X45X78910XXXXXX1415
Your entered matrix is :X 2 X 4 5X X 8 9 XXXX XX 13 14 XX
Your Transposed XXXXXX is :X X 112 7 XX3 8 13X X XX5 XX 15
XXX maximum XX XXX XXX column XXXXXXXX:XX 12 XX XX XXThe average XX XXX the rows XXXXXXXX:X.X 8.0 13.0