trying to get the maximum location in my matrix of 4 columns and 3 rows. can anyone help point me in the right direction

import java.util.*;
public class Program3{
    public static void main(String[] args){

        double [][] m = createArray();
        double [] colsum= new double [m[0].length];
        for(int i=0;i<m[0].length;i++)
            colsum[i]= sum(m,i);
            printResult(m, colsum);
            double [][] maximum;

    }
    public static double[][] createArray(){
        Scanner input=new Scanner (System.in);
        double [][] m=new double[3][4];
        System.out.print(" please enter a "  +    m[0].length   +    "-by-"   +  m.length  +   " matrix row by row: " );
        for(double i=0;i<m.length;i++)
            for(double j= 0; j<m[0].length; j++)
                m[(int) i][(int)j]=input.nextDouble();
        return m;

    }
    public static double sum(double[][] m, int columnIndex){
        double total=0;
        for (int row =0; row<m.length;row++)
            total+=m[row][columnIndex];
        return total;

    }
    public static void printResult(double[][] m, double[] sum){
        for (int row =0; row<m.length; row++){
            for (int column= 0;column<sum.length; column++){
                System.out.printf(   "    %2.1f", m[row][column]);
                }
                System.out.println("");
        }
        System.out.print("Sum:");

        for (int column= 0;column<sum.length; column++){
            System.out.printf("%4.1f  ", sum[column]);

            }
        System.out.print("\n");
        System.out.println("Program 3 is developed by Pottertr");}

        public static double max(double[][] m, int columnIndex){
            int maximum=0;
             for (int i = 0; i < m.length; i++) {
                    double max = -1;
                    for (int j = 0; j < m[i].length; j++)
                        if (m[(int)i][(int)j] > max)
                            max = m[(int)i][(int)j];

            }
            return maximum;



        }
    }


    that is the code i have so far and the out put should look like this 
    the output should state .
    the maximum number is 9.5 at row 2,column 0.
    the minimum number is 1.1 at row 2 column 3.

basically, what you need to do, is iterate over your array(s). so, a bit like this:

int max = fromMyArray[0][0];
int iPos = 0; 
int jPos = 0;
for ( int i = 0; i < outerLength; i++){
  for ( int j = 0; j < inner length; j++ ){
    if ( fromMyArray[i][j] > max ){
      max = fromMyArray[i][j];
      iPos = i;
      jPos = j;
    }
  }
}

This should at least give you an idea of how to start.

This article has been dead for over six months. Start a new discussion instead.