public class Lab15
{
public static void main(String[] args)
{
double [][] values = { {1.1, 2.2, 3.3, 4.4, 5.5 },
{6.6, 7.7, 8.8, 9.9, 10 },
{11.11, 12.12, 13.13, 14.14, 15.15 } };
double [] rowMaxes = rowMaximums(values);
double [] colMaxes = colMaximums(values);
System.out.println("Rows:");
for(int r = 0; r < rowMaxes.length; r++)
System.out.printf("The max of row %d is %.2f\n", r, rowMaxes[r]);
System.out.println();
System.out.println("Cols:");
for(int c = 0; c < colMaxes.length; c++)
System.out.printf("The max of col %d is %.2f\n", c, colMaxes[c]);
System.out.println();
}
public static double[] colMaximums(double [][] grid)
{
int rows = grid.length;
int cols = grid[0].length;
double [] maximums = new double [cols];
for(int r = 0; r < rows; r++)
for(int c = 0; c < cols; c++)
if(maximums[c] < grid[r][c])
maximums[c] = grid[r][c];
return maximums;
}
public static double[] rowMaximums(double [][] grid)
{
int rows = grid.length;
int cols = grid[0].length;
double [] maximums = new double [rows];
for(int r = 0; r < rows; r++)
for(int c = 0; c < cols; c++)
if(maximums[r] < grid[r][c])
maximums[r] = grid[r][c];
return maximums;
}
}