0

I'm trying to randomly select 6 numbers for a lottery application. Then add the numbers to an array. When I try to display the information contained within the array, it returns [I@63376afa. If I display randomInt outside of an array it displays correctly, but that isn't added to an array. If I try to add randomInt to an array after the for loop has been processed I get an error Type mismatch can't convert int to int[] which makes sense.

import java.util.Random;
public class PracRandom1 
{
    public static void main(String[] args) 
    {
        int randomInt=0;
        int[] numArray = new int[randomInt];
        int[] array = new int[5];
        Random randomNum = new Random();{
            for (int i = 0; i <= array.length; ++i){
            randomInt = 1+randomNum.nextInt(6); 
                        System.out.println("Array Random numbers: " + numArray);
            }
}}}
gdoron
  • 147,333
  • 58
  • 291
  • 367
Gryphin
  • 3
  • 2

2 Answers2

1

Check out java.util.Arrays.toString().

Arrays do not have a terribly useful toString() implementation out of the box.

Arthur Dent
  • 785
  • 3
  • 7
0

To get a human-readable toString(), you must use Arrays.toString(), like this:

System.out.println(Arrays.toString(array));

Java's toString() for an array is to print [, followed by a character representing the type of the array's elements (in your case I for int), followed by @ then the "identity hash code" of the array (think of it like you would a "memory address").

This sad state of affairs is generally considered as a "mistake" with java.

See this answer for a brief list of other "mistakes".

Community
  • 1
  • 1
Bohemian
  • 412,405
  • 93
  • 575
  • 722