0

Hi there I'm trying to make a lottery, generating 6 random numbers adding them to an array and then getting a users numbers and adding them to an array. This is what I've tried so far.

Heres my lottery class,

class Lottery {
    Random rand = new Random();
    // generating lottery numbers
    int cpnum;
    int[] allCpNumbers = new int[100];

    // bets placed
    int betsPlaced;
}

Here's my for loop to generate the random numbers and add them into my array

// printing lottery numbers
for(int i = 0; i <= 6; i++) {
    lottery.cpnum = rand.nextInt(50) + 1;
    lottery.allCpNumbers[i] = lottery.cpnum;
}

When printing the random numbers it gives me this

System.out.println(lottery.allCpNumbers);

Output:

[I@1b6d3586

I want it to be a set of 6 random numbers arranged like 3,13,10,43,12 etc.

Tomhass
  • 13
  • 4
  • JoeC - thanks for that link, I thought it was an issue with the memory used for the array, didn't think it was a problem with printing – Tomhass Apr 22 '18 at 17:03

2 Answers2

0
System.out.println(Arrays.asList(loterry.allCpNumbers))

or

Arrays.asList(loterry.allCpNumbers).stream().forEach(System.out.println);
Antoniossss
  • 31,590
  • 6
  • 57
  • 99
0

Put sysout inside for loop

     System.out.println(lottery.allCpNumbers[I])

Try below concept in your case

    String[] array = new String[] {"John", "Mary", "Bob"};
    System.out.println(Arrays.toString(array));

Output:

[John, Mary, Bob]

Onic Team
  • 1,620
  • 5
  • 26
  • 37