Basically I am trying to return an element from an 2d array in java. I have created a separate Matrix class and inside the class I want to write a get_element method which would take as input the coordinates of the element I want from the matrix and the matrix itself, however I am not sure how to do this.
public static double get_element(Matrix A, double m , double n)
{
for(int i=0;i
for(int j=0;j
return A.data[m][n];
}
This is how my code look right now. And I get an error that says lossy conversion between double and int.
解决方案
You don't need the loop. Also, you need to convert the double to int
return A.data[(int) m][(int) n];
Alternatively (better), you change the method signature:
public static double get_element(Matrix A, int m , int n) {
return A.data[m][n];
}