Respuesta :
Answer:
Output:-
Enter the five digit lottery number
Enter the digit 1 : 23
Enter the digit 2 : 44
Enter the digit 3 : 43
Enter the digit 4 : 66
Enter the digit 5 : 33
YOU LOSS!!
Computer Generated Lottery Number :
|12|38|47|48|49|
Lottery Number Of user:
|23|33|43|44|66|
Number Of digit matched: 0
Code:-
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Lottery {
int[] lotteryNumbers = new int[5];
public int[] getLotteryNumbers() {
return lotteryNumbers;
}
Lottery() {
Random randomVal = new Random();
for (int i = 0; i < lotteryNumbers.length; i++) {
lotteryNumbers[i] = randomVal.nextInt((50 - 1) + 1);
}
}
int compare(int[] personLottery) {
int count = 0;
Arrays.sort(lotteryNumbers);
Arrays.sort(personLottery);
for (int i = 0; i < lotteryNumbers.length; i++) {
if (lotteryNumbers[i] == personLottery[i]) {
count++;
}
}
return count;
}
public static void main(String[] args) {
int[] personLotteryNum = new int[5];
int matchNum;
Lottery lnum = new Lottery();
Scanner input = new Scanner(System.in);
System.out.println("Enten the five digit lottery number");
for (int i = 0; i < personLotteryNum.length; i++) {
System.out.println("Enter the digit " + (i + 1) + " :");
personLotteryNum[i] = input.nextInt();
}
matchNum = lnum.compare(personLotteryNum);
if (matchNum == 5)
System.out.println("YOU WIN!!");
else
System.out.println("YOU LOSS!!");
System.out.println("Computer Generated Lottery Number :");
System.out.print("|");
for (int i = 0; i < lnum.getLotteryNumbers().length; i++) {
System.out.print(lnum.getLotteryNumbers()[i] + "|");
}
System.out.println("\n\nLottery Number Of user:");
System.out.print("|");
for (int i = 0; i < personLotteryNum.length; i++) {
System.out.print(personLotteryNum[i] + "|");
}
System.out.println();
System.out.println("Number Of digit matched: " + matchNum);
}
}
Explanation: