-2

so basically this is my code:

Random randomgenerator = new Random(); int[] arr = new int[8];

    for (int i = 0; i < arr.length; i++) {
        arr[i] = randomgenerator.nextInt(100);
    }

    System.out.println(arr);
}

}

and this is what appears in the console :

[I@106d69c

I really need help with this, I am probably doing some terrible mistake because I am new to Java coding.

  • 1
    Use `Arrays.toString(yourArrayHere)` – azurefrog Jan 18 '16 at 16:32
  • Just for you to know, if you see something like `xx@yyyyyy` it's likely to be an object's address, not its content and the `xx` can even tell you its type. For example yours is `|i`, it means `array of integers`. – Gaël J Jan 18 '16 at 16:35
  • 1
    @Gaël Just a friendly FYI, the default toString method does not show the objects memory address, but the object's classname and it's hashcode combined. [See here](http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#toString()) for details. – Mage Xy Jan 18 '16 at 16:38

1 Answers1

3

You are printing the whole array, so the default toString method of the array gets called (and it prints a hashcode and the type of the array, nothing useful for you).

What you want is something like :

for (int i = 0; i < arr.length; i++) {
        System.out.println(arr[i]);
    }

Or better yet as @azurefrog said :

 System.out.println(java.util.Arrays.toString(arr));
Arnaud
  • 17,229
  • 3
  • 31
  • 44