2013-03-02 2 views
-4

본질적으로 이러한 메서드를 호출하려고 할 때 오류가 발생하지만 기본적으로 Java에서 배열의 배열로 몇 가지 기본적인 작업을 수행하는 3 가지 메서드가있는 클래스가 있습니다. 문제는 지금이 내가 한 주입니다 임은 확실 ... 그 바보 같은 기본적인 실수 :(자바에서 메서드를 호출 할 때 오류가 발생했습니다

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) 
+3

변수의 인스턴스에 액세스 할 수 Matrix 클래스의 인스턴스를해야합니까? – mindandmedia

+0

모두 다시 작성하십시오 .... – jdb

답변

4

Exception in thread "main" java.lang.Error: Unresolved compilation problem: m cannot be resolved to a variable at testMatrix.main(testMatrix.java:5)

는, 당신은 당신이지고 어떤 오류

Matrix.negate(new Matrix().m); 
관련 문제