I'm trying to use an array to print out 6 numbers out of 42 since it's a lotto code
Here's the question the lecturer wants me to do:
Write a Java program to achieve the following:
Declare an array of type int of size 6
Randomly generate your lotto numbers for next week and store them
in the array using a loop…good luck!
Print the array to the screen
import java.util.Random;
public class W2P8{
public static void main(String[]args){
int[] randomNumbers = new int[6];
Random rn = new Random();
for (int i = 0; i < randomNumbers.length; i++)
{
int randomInt = rn.nextInt(42) + 1;
System.out.println(randomInt);
}//end of for loop
}//end of main
}//end of class
This prints out 6 random numbers but prints out duplicates.