Hi guys,
I need to create the following program:
- 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. - Declare an integer to count the number of matching lottery numbers.
- 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. - 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 but am consufed and lost as can be, how do i compare the arrays?
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Lab6Array {
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: " + Arrays.toString(HardCoded));
for(int i = 0; i < HardCoded.length; i++){
if(HardCoded[i] == UserInput){
}
}
}
}