I am working on this lottery code but I am facing an endless run. I would like to point out what could be wrong with the code and how it should be done to improve it. Thank you. The question is "to generate two-digit number lottery". There are two different numbers in the number. (Hint: Generate first digits.) Use a loop to keep the second digit consistent, unless it is no different from the first digit. Public square lottery 1 {public static zero main (string [] args) {// scanners create scanners = new scanners (system.); // Create a two-digit random lottery number int lottery = (int) (Math.rendum () * 100); // TODO code application logic here // lottery Intel First and Second LotteryDigit1 = Lottery / 10; Int Lottery Deit 2 = Lottery% 10; While (lotterydegit2! = LotteryDiGit1) {Lotterydigit2 = lottery% 10;} / Prompt User System for the estimated number Out.print ("Enter two digit numbers:"); Int estimate = s.nextInt (); Int guessdigit1 = guess / 10; Int guessdigit2 = estimate% 10; // Comparison E Lottery and if (guessdigit1 == lotterydeget1 & amp; amp; guessdigit2 == lotterydigit2) {System.out.println ("You've just won $ 10,0000"); } And if (EstimateDigit1 == Lotterie Digit 2 & amp; amp; amp; amp; estimate = 2 == lotterydegit1) {System.out.println ("You've won $ 5,000"); } Else if (guessdigit1 == lotterydigit1 || guessdigit1 == lotterydigit2+ estimationDigit2 == lotterydegit1 || estimationDigit2 = lotterydegit2) {System.out.println ("you've won $ 1,000"); } Else {System.out.println ("You have not won anything"); } System.out.println ("lottery number is" + "" + lottery + "and your guess" seems ");}}
You want them to make different changes
while (lotterydegit2! = Lotterydegit1) {lotterydegit2 = lottery% 10; }
while (lotterydegit2 == lotterydeget1) {lotterydegit2 = lottery% 10;}
< / Div>
No comments:
Post a Comment