Skip to main content

Posts

Showing posts with the label matrix

Trying to get the max/min in array

Im trying to get the min value in a column in the row of the max value. Im trying to using for loops but its not working. Let say a matrix A: 3 4 5 2 3 4 1 2 3 I want the program to find the max value in the [0]th row then find the min value in the colunm of the max. So result should be : max of row [0] = 5, min of column [2] = 3. I then want it to do the same of all the rows, that why I ysed a while loop. Here is the matrix: public int[][] createMatrix(int a, int b){ Scanner inputm = new Scanner(System.in); A = new int[a][b]; System.out.println("Enter elements for matrix A : "); for (int i=0 ; i < A.length ; i++){ System.out.println("Enter numbers for " + i +"th row"); for (int j=0 ; j < A[i].length ; j++){ A[i][j] = inputm.nextInt(); } } return A; } public int[][] displayMatrix(){ System.out.println("Matrix A: "); for (int i=0 ; i < A.length ; i++) { System.out.println(); for (int j=