处理/初始化2D数组(Java)

时间:2016-09-22 00:48:12

标签: java arrays multidimensional-array

我一直在尝试为我的CS课程编写程序并遇到问题。在下面的代码中,我一直收到initializeArray(firstArray)initializeArray(secondArray)的错误消息。

消息显示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;
            }



        }

    }

1 个答案:

答案 0 :(得分:0)

你有一个错字:

intializeArray

initializeArray

以不同的方式拼写