import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Random random = new Random();
Scanner in = new Scanner(System.in);
int[] lottery = new int[5];
int[] user = new int[lottery.length];
for (int i = 0; i < lottery.length; i++) {
lottery[i] = random.nextInt(10);
}
for (int i = 0; i < user.length; i++) {
do {
System.out.print(i + 1 + ": ");
user[i] = in.nextInt();
} while (user[i] < 0);
}
StringBuilder matchingDigits = new StringBuilder();
int count = 0;
System.out.print("Lottery: ");
for (int i = 0; i < lottery.length; i++) {
System.out.print(lottery[i] + " ");
if (lottery[i] == user[i]) {
matchingDigits.append(i).append(" ");
count++;
}
}
System.out.println("\nThe number of matching digits: " + matchingDigits);
if (count == lottery.length) {
System.out.println("You are a grand prize winner!!!");
}
}
}
Comments
Leave a comment