Revise Lottery.java, to generate a lottery of a two digit number.The two digits
ID: 3609765 • Letter: R
Question
Revise Lottery.java, to generate a lottery of a two digit number.The two digits in the number are distinct. (Hint: Generate thefirst digit. Use a loop to continuously generate the second digituntil it is different from the first digit.)import java.util.Scanner;
public class Lottery
{
public static void main(String[] args)
{
int lottery =(int)(Math.random()*100);
Scanner input = newScanner(System.in);
System.out.print("Enteryour lottery pick (two digits): ");
int guess =input.nextInt();
if (guess ==lottery)
System.out.println("Exact match: you win $10,000");
else if (guess % 10 ==lottery/10 && guess/10 == lottery % 10)
System.out.println("Match all digits: you win $3,000");
else if (guess % 10 ==lottery/10 || guess % 10 == lottery % 10 || guess/10 == lottery/10|| guess/10 == lottery % 10)
System.out.println("Match one digit: you win $1,000");
else
System.out.println("Sorry, no match");
}
}
Explanation / Answer
importjava.util.Scanner;
public class untitled1
{
public static void main(String[] args)
{
int lottery = (int)(Math.random()*10);
int num2=lottery;
while(num2==lottery)
num2=(int)(Math.random()*10);
lottery=lottery*10+num2;
Scanner input = newScanner(System.in);
System.out.print("Enter your lottery pick (two digits): ");
int guess = input.nextInt();
if (guess == lottery)
System.out.println("Exact match: you win $10,000");
else if (guess % 10 == lottery/10 && guess/10 == lottery %10)
System.out.println("Match all digits: you win $3,000");
else if (guess % 10 == lottery/10 || guess % 10 == lottery % 10 ||guess/10 == lottery/10 || guess/10 == lottery % 10)
System.out.println("Match one digit: you win $1,000");
else
System.out.println("Sorry, no match");
System.out.println("Lottery number is "+lottery);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.