Reputation: 13
Hello I am developing a mathematical library for java I wrote methods Matrix(), setMatrix (), getMatrix () is required to getmatrix() method returned the entire two-dimensional array more precisely all its values
static int[][] getMatrix(){//return matrix
return matrix;
}//why returns a reference instead of an array value ? [[I@15db9742 only this
class Mathematik {
private static int[][] matrix;
private static int line_0;
private static int column_0;
static int Matrix(int line, int column){//Matrix
for(int l=0; l<line; l++){//line
for(int j=0; j<column; j++){//column
line_0=l;
column_0=j;
matrix=new int[l][j];
}
}
return matrix;
}
static int setMatrix(int num){//fill matrix
for(int l=0; l<line_0; l++){//line
for(int j=0; j<column_0; j++){//column
matrix[l][j]=num;
}
}
return 0;
}
static int[][] getMatrix(){//return matrix
return matrix;
}//why returns a reference instead of an array value ? [[I@15db9742 only this
}
class Activity{
Mathematik A=new Mathematik();//call the class
public static void main(Strin[] args){
A.Matrix(3,3)//create matrix
A.setMatrix(10)//to fill in the matrix
System.out.println(""+A.getMatrix());//Writes the grid values to a string
}
}
arrays [1a, 2a, 3a.....a]
the method getMatrix() is required to return all values of the array
Upvotes: 0
Views: 120
Reputation: 8371
Because you are requiring the array and that what is returning is correct . You must convert that array to String .Try using Arrays.toString(matrix);
The current value that is getting returned is the representation in memory for the matrix value .
Please refer to this link as JB Nizet mentions
Upvotes: 0
Reputation: 40034
It does return the matrix. You can't print the matrix like you are trying. You need to print each value. Or you can simply iterate over the rows and then pass each one to Arrays.toString()
to display them. You may also want to write your own display routine for your library.
Upvotes: 1