2017-04-16 9 views
0

行列サイズを取得しようとするとコンパイルエラーが発生します。インストラクターが私にそれを変えないように言われたので、私は主な方法に間違っていることは何もわかりません。だから私は何かがgetMatixSizeメソッドで間違っていると思います。プログラムのコンパイラ計算:ユーザ入力を使用して行列を作成しようとすると、コンパイルエラーが発生する。 Java

error: method getMatrixSize in class TesterProject cannot be applied to given types;

import java.util *;既にプログラムに入力されています。

public class TesterProject 
{ 
    public static void main(String [] args) 
    { 
     int n = getMatrixSize(); 
     int[][] m = makeAndFillMatrix(n); 
     printMatrix(m); 
    } 
    public static int getMatrixSize(int n) 
    { 
     Scanner S = new Scanner(System.in); 
     System.out.println("give me a int to create the matrix"); 
     int n = S.nextInt(); 
     return n; 
    } 
} 
+0

まあ、 'getMatrixSize(int型n)は' 'int'引数を_requires_が、あなたはそれを呼び出すときに引数を指定しません。それを超えて、 'getMatrixSize()'は渡された値を実際には使用しないので、署名を 'public static int getMatrixSize()'に変更して動作させることができます。 –

+0

うわー、ありがとう、他のユーザーに助けてくれてありがとう! – IDK

答えて

1

あなたは引数なしでint n = getMatrixSize();を呼び出そうとしますが、引数として整数を受け入れるpublic static int getMatrixSize(int n)あなたの方法しています。それがエラーを起こす理由です。

getMatrixSize()のパラメータからint nを削除すると、コードは正常に動作します。

0

これは、getMatrixSizeintを引数にとり、それを与えていないためです。

int n = getMatrixSize(5); //pass some int 

はまた、あなたのgetMatrixSizeで、nはすでに宣言されています。

public static int getMatrixSize(int n) 
{ 
    Scanner S = new Scanner(System.in); 
    System.out.println("give me a int to create the matrix"); 
    int n = S.nextInt(); //error, n is already declared in the arguments. 
    return n; 
} 

または引数を削除し、それをすべて修正:

public static int getMatrixSize() // removed argument