Trying to pass an array to a function within the same scope and receiving expression expected & ; expected errors. Confused as a beginner. Thanks

Viewed 27

Screenshot

import java.util.*;

public class Test {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the size of the array : ");
        int n = in.nextInt();
        int[][] arr = new int[n][n];

        public static void getArray(int[][] array){
            System.out.print("Enter the elements of the array : ");
            for (int i = 0; i < array.length; i++) {
                for (int j = 0; j < array.length; j++) {
                    array[i][j]= in.nextInt();
                }
            }
    }
}

I've only began learning java for 2 days so I'm completely stumped. Kindly help me resolve this. Here I'm trying to create a program where we create an array and 2 functions to fill the array and display the array, the latter 2 of which is to be done by console input.

0 Answers
Related