0

This is the problem, how to know the index of a matrix using a method in Java?

package myMethods;

public class MyMath {

public static int[] indexOfMatrix(int[][] M,int toFind) {
        int index[]= {-1,-1};
        for(int rows=0; rows<M.length; rows++) {
            for(int columns=0; columns<M[rows].length; columns++) {
                if(toFind==M[rows][columns]) {
                    index[0]=rows;
                    index[1]=columns;
                    return index;
                }
            }
        }
        return index;
    }   

public static void main(String[] args) {
        int[][] d={{3,7,8},{4,5,6},{2,1,0}};
        System.out.println(indexOfMatrix(d,4));
}

}
I expect a number to be the output not "[I@15db9742"                                                

Gloria S
  • 13
  • 2

1 Answers1

0

If it printing the array in a readable format, then simplest would be -

System.out.println(Arrays.toString(indexOfMatriz(d,4)));

Java Documentation

Subhrajyoti Majumder
  • 40,646
  • 13
  • 77
  • 103