Question: Revise Listing 3.8, Lottery.java, to generate a lottery of a twodigit number. The two digits in the number are distinct.? Listing 3.8 1 import java.util.Scanner;

Revise Listing 3.8, Lottery.java, to generate a lottery of a twodigit number. The two digits in the number are distinct.?

Listing 3.8

1 import java.util.Scanner; 2 3 public class Lottery { public static void

main(String[] args) { 4 // Generate a lottery number 5 int lottery

1 import java.util.Scanner; 2 3 public class Lottery { public static void main(String[] args) { 4 // Generate a lottery number 5 int lottery = (int)(Math.random() * 100); // Prompt the user to enter a guess Scanner input = new Scanner (System.in); System.out.print("Enter your lottery pick (two digits): "); int guess = input.nextInt(); 8 10 11 12 13 // Get digits from lottery int lotteryDigitl = lottery / 10; int lotteryDigit2 = lottery % 10; 14 15 16 17 18 // Get digits from guess int guessDigit1 = guess / 10; int guessDigit2 = guess % 10; 19 20 21 22 23 System.out.printIn("The lottery number is " + lottery); // Check the guess if (guess == 1ottery) System.out.print1n("Exact match: you win $10,000"); else if (guessDigit2 == lotteryDigitl && guessDigitl =- lotteryDigit2) System.out.println("Match all digits: you win $3,000"); else if (guessDigitl == lotteryDigitl || guessDigitl || guessDigit2 == lotteryDigitl || guessDigit2 System.out.println("Match one digit: you win $1,000"); 24 25 26 27 28 29 30 lotteryDigit2 31 32 lotteryDigit2) 33 else System.out.println("Sorry, no match"); 34 35 36 37 } Enter your lottery pick (two digits): 15 -Emter The lottery number is 15 Exact match: you win $10,000 Enter your lottery pick (two digits): 45 Jenter The lottery number is 54 Match all digits: you win $3,000 Enter your lottery pick: 23 - Enter The lottery number is 34 Match one digit: you win S1,000 Enter your lottery pick: 23 -Enter The lottery number is 14 Sorry: no match line# 11 14 15 18 19 33 variable lottery 34 guess 23 lotteryDigitl lotteryDigit2 4 guessDigitl guessDigit2 Output Match one digit: you win $1,000

Step by Step Solution

3.42 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Output 80 81 82 83 84 85 86 87 88 89 Program that finds lottery Compile Javac Lotteryj... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!