0

i looked around a bit here on the site but found nothing that seemed to help me on this problem.

so here's my little issue. lets say i have a function that looks like this

public static void main(String args[])
{    
  int[][] array = new int[9][9];

  createArray(array);
}

and i'm trying to pass array into this method so that i can initialize it with input that was read from the console.

public static void createArray(int[][] array)
{
  Scanner input = new Scanner(System.in);
  int i = 0;
  int j = 0;

  for(i = 0; i < 9; i++)
  {
    for(j = 0; j < 9; j++)
    {
      array[i][j] = input.nextInt();
    }
  }

  input.close();
}

i would think that this would work, since java passes arrays by reference so that means that the createArray() method is receiving the memory address of the array back in main, and therefore any changes here affects the original one in main.

but for some reason that i'm not seeing, running this gives me these errors, and i dont understand what i'm doing wrong enter image description here

cooldude22
  • 27
  • 8
  • Look carefully at the exception, then look up the Javadoc for `NoSuchElementException`, and then look at the stack trace to see what code is throwing the exception (line 81). It has nothing to do with array accesses. – Jim Garrison Jan 17 '18 at 04:59
  • What is on the line 81? The method createBoard? And try once making array as private entity and then using it. – Nikhil Pareek Jan 17 '18 at 05:05
  • Line 81 is clearly `array[i][j] = input.nextInt();` – Jim Garrison Jan 17 '18 at 05:09

0 Answers0