2016-09-22 7 views
0

私はCSクラスのプログラムを作成しようとしていて、問題があります。下のコードでは、私はinitializeArray(firstArray)initializeArray(secondArray)にエラーメッセージを表示し続けています。2D配列の処理/初期化(Java)

メッセージにはthe method initializeArray(int[][]) is undefined for type processArrayと表示されます。誰でも私がここで間違っていることを私に説明することはできますか?私は私のprocessArrayメソッドでinitializeArrayメソッドを呼び出すことができる必要があります。

public class ProcessArray { 


    // The constructor for the class: it initializes the attributes "rows" and "columns", and also completes the 
    // declarations for the two arrays using the dimensions received. It then calls a private method in the class 
    // to set the values in both arrays to 0. 
    public ProcessArray (int rows, int columns){ 

     int[][] firstArray = new int[rows][columns]; 
     int[][] secondArray = new int[rows][columns]; 

     initializeArray(firstArray); 
     initializeArray(secondArray); 

    } 



    // This private utility method sets the values in both arrays to 0. 
    private void intializeArray(int[][] array){ 

     int rows = array.length; 
     int columns = array[0].length; 

     for(int i = 0; i < rows; i++){ 
      array[i][0] = 0; 

      for(int j = 0; j< columns; j++){ 
       array[i][j] = 0; 
      } 



     } 

    } 
+0

異なる方法で綴られています。また、配列[i] [0] = 0;冗長です。 – HomeIsWhereThePcIs

+0

あなたの冗長な声明が私を不思議に思った。そのコードはその声明なしでまったく同じことをするでしょうか? – Daniel

+0

はい。あなたの頭の中で繰り返します。最初の反復ではi = 0なので、array [i] [0]は実際には配列[0] [0] = 0です。行配列[i] [j] = 0に来ると、iとjの両方が0なので、array [0] [0] = 0をもう一度実行します。 – HomeIsWhereThePcIs

答えて

0

あなたはタイプミスがあります

intializeArray

initializeArray

はあなたがメソッド名のタイプミスを持って

+0

うわー、私は馬鹿のように感じる。他の理由を探して時間を割いてくれてありがとう – Daniel