0

I am currently having some trouble on one of my assignments. I want to use a scanner to read the input file and put each number in the file into a int array. I found an answer through How to read integer values from text file. But when I used this code it returned something weird. Below is my input, code, and output.

20401
11087
62176
70095
20947
20098
90914
53475
51251
20065

Scanner s = new Scanner(new File(fileName));
    int[] list = new int[10];
    int i = 0;
    while(s.hasNextInt())
    {
        list[i] = s.nextInt();
        i++;
    }
    s.close();
    System.out.print(list);

The output is [I@42a57993. Can someone please explain what I might be doing wrong.

Soultion: System.out.println(Arrays.toString(list)); Returns it properly. Thanks

Bodhe
  • 9
  • 2
  • You are printing the list object's toString method. – Essej Feb 19 '18 at 20:39
  • The duplicate doesn't mention using an `ArrayList` instead of an array, which imo is actually the simplest way to deal with the OP's problem. – markspace Feb 19 '18 at 20:41

0 Answers0