You will take in a 5 digit lottery number and compare it to a winning lottery number.
If the input lottery number has a certain numbers correct you will tell the user how much they have won.
You should follow these steps:
1.Declare 2 5 element integer arrays. (a) One should be for the winning lottery number (hard code this as 12, 35, 34, 2, 5). (b) The other should be for the user’s lottery number input.
2.Declare an integer to count the number of matching lottery numbers.
2.Declare an integer to count the number of matching lottery numbers.
3.Prompt the user to enter their 5 digit lottery number using a for loop and put their numbers in the user’s lottery number array.
4.Compare the elements of the two arrays using a for loop and increment the counter variable declared above when there is a match.
Using the value held in the counter variable, display how much the user has won.
(a) 0 matching numbers: $0
(b) 1 matching number: $1
(c) 2 matching numbers: $50
(d) 3 matching numbers: $1,000
(e) 4 matching numbers: $50,000
(f) 5 matching numbers: $90,000,000
I have the code below so far:
public static void main(String[]args){
final int [] HardCoded = {12, 35, 34, 2, 5};
int UserInput [] = new int[5];
Scanner input = new Scanner(System.in);
System.out.println("Please enter 5 Numbers. ");
System.out.print("Numbers [0]: ");
UserInput [0] = input.nextInt();
System.out.print("Numbers [1]: ");
UserInput [1] = input.nextInt();
System.out.print("Numbers [2]: ");
UserInput [2] = input.nextInt();
System.out.print("Numbers [3]: ");
UserInput [3] = input.nextInt();
System.out.print("Numbers [4]: ");
UserInput [4] = input.nextInt();
System.out.println("Lottery Numbers are: " + HardCoded);
}
}
However, the issue is that the hardcoded value will not print and int UserInput [] = new int[5]; has to be 4 but i get an error so i have to put in 5?