[Solved] how do i return the array from method?


To answer your question “How to return the matrix”: you are already doing it the right way. As you can see from the comments so far, the problem lies in the declaration of A.

A is declared and initialized inside the for-loop:

int [][]A = new int [size_num][size_num];

Hence its visibility is limited to the for-loop. To make A visible to the already existing return statement you have to move its declaration:

int size_num = Integer.parseInt(size);
int[][]  A = new int[size_num][size_num];
if (size_num > 1 && size_num < 4) {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  for(int row = 0; row < size_num ; row++)
    for(int col = 0 ; col < size_num ; col++){
        String ipS = br.readLine();
        int input_value = Integer.parseInt(ipS);
        A[row][col] = input_value;
  }
} else {
  System.out.println("invalid matrix size!");
}
return A; 

1

solved how do i return the array from method?