문제

For some reason, I can't get my method to display a previously mentioned array. The only issue is in my first line. The error code is: "illegal start of expression". What am I doing wrong?

    public static void display(int matrix[][]) {
        for (int row = 0; row < matrix.length; row++) {
            for (int col = 0; col < matrix[row].length; col++) {
                System.out.print(matrix[row][col] + " ");
            }
            System.out.println();
        }
    }
도움이 되었습니까?

해결책

your method has to be inside the class, but outside any other method.
if this method is within the main method, then your code will look something like this:

public class name
{
    public static void main(String[] args)
    {
         //code
         yourmethod(parameter); //*somewhere in your code*
    }

    public static void yourmethod(parameters p)
    {
         //code
    }
}

if it's within a regular class with no main method

public class name
{
    public name()
    {
        //code
    }

    public void yourmethod(parameters p)
    {
        //code
    }

    //other methods
}

다른 팁

The error is not in that method, surely you missed a } before

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top