我有一个有 3 个方法的类,它基本上用 Java 中的数组数组做一些基本的东西,虽然当我试图在我的 main 中调用这些方法时我得到一个错误..谁能告诉我问题是什么......我确定它一些愚蠢的基本错误:(
class Matrix {
double[][] m = { {2,4,31,31},
{3,3,21,41},
{1,2,10,20},
{3,2,20,30} };
public static void negate(double[][] m){
int r = m.length;
int c = m[r].length;
double[][] n = new double[c][r];
for(int i = 0; i < n.length; ++i) {
for(int j = 0; j < n[i].length; ++j) {
n[i][j] = (m[i][j])*-1;
}
}
}
public static void transposeMatrix(double[][] m){
int r = m.length;
int c = m[r].length;
double[][] t = new double[c][r];
for(int i = 0; i < r; ++i){
for(int j = 0; j < c; ++j){
t[j][i] = m[i][j];
}
}
}
public void print(double[][] n, double[][] t){
int r = m.length;
int c = m[r].length;
for(int i = 0; i < r; ++i){
for(int j = 0; j < c; ++j){
System.out.print(" " + n[i][j]);
}
System.out.println("");
}
for(int i = 0; i < r; ++i){
for(int j = 0; j < c; ++j){
System.out.print(" " + t[i][j]);
}
System.out.println("");
}
}
}
现在这是我的主要..
public class testMatrix {
public static void main(String[] args){
Matrix.negate(m);
}
}
提前感谢您的任何意见!
这是错误...
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
m cannot be resolved to a variable
at testMatrix.main(testMatrix.java:5)