Write a program that simulates a lottery The program should

Write a program that simulates a lottery. The program should have an array of 5 integers named winning Digits, with a randomly generated number in the range of 0 through 9 for each element in the array. The program should ask the user to enter 5 digits and should store them in a second integer array named player. The program must compare the corresponding elements in the two arrays and count how many digits match. For example, the following shows the winning Digits array and the Player array with sample numbers stored in each. There are two matching digits, elements 2 and 4. Once the user has entered a set of numbers, the program should display the winning digits and the player\'s digits and tell how many digits matched.

Solution

package chegg2;

import java.util.Scanner;

public class RandomNum {

   public static void main(String args[]){
      
       int WinningDigits[]=new int[5];
       int player[]=new int[5];
       int count=0;
       Scanner scanner = new Scanner(System.in);
       System.out.println(\"Enter 5 digits\");
  
       for(int i=0;i<5;i++){
           WinningDigits[i]=(int)(Math.random() * 10);
           player[i]=Integer.parseInt(scanner.nextLine());
       }
       scanner.close();
       System.out.print(\"Winning Digits\");
       for(int j=0;j<5;j++){
           System.out.print(\"\\t\"+ WinningDigits[j]);  
       }
       System.out.println();

       System.out.print(\"player \\t\");

       for(int j=0;j<5;j++){
           System.out.print(\"\\t\"+ player[j]);  
       }
       System.out.println();
      
       for(int j=0;j<5;j++){
           if(WinningDigits[j]==player[j]){
               count++;
           }
      
       }
       System.out.println(\"Number of matching digits: \"+count);
      
   }
}

 Write a program that simulates a lottery. The program should have an array of 5 integers named winning Digits, with a randomly generated number in the range of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site