Question: I have this method (not my main method) but it is part of a lottery program. Here I am asking the user to pick 5

I have this method (not my main method) but it is part of a lottery program. Here I am asking the user to pick 5 numbers or have 5 numbers generated for them. The lottery ticket can only have numbers 1 through 20 and no repeated values. How do I check to see if the numbers are repeated and how do I change the values if they are repeated?

public static int[] lottery() { int[] array = new int[5]; Scanner keyboard = new Scanner(System.in); Random randomNumbers = new Random(); //Ask the user if they would like to pick their own numbers System.out.println("Would you like to enter your own lottery numbers? Select 1 for yes or select 2 for no") int user = keyboard.nextInt(); //validate user input while(user<1 || user>2) System.out.println("Invalid number. Please enter 1 for yes or 2 for no"); user = keyboard.nextInt(); //if user selects yes, allow them to enter their own numbers if (user == 1) { //Get the lottery numbers from user for (int i=0; i=20) { System.out.println("Invalid number. Please enter a value 1 through 20" + (array+1)); //page439 //assign value to array userticket[array] = keyboard.nextInt() //Check to see if the user entered the same number //for(int s=0; i= } } } //if user chooses no, randomly generate numbers for them else if(user == 2) { for(int i=0; i

please use java

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!