0% found this document useful (0 votes)
88 views2 pages

Lottery

This Java code simulates a lottery game by generating a random two-digit number and prompting the user to guess it. It uses logic to compare the digits of the guessed and randomly generated numbers to determine different prize amounts: the user wins $10,000 for a correct guess, $3,000 if the digits match but are swapped, $100 if any single digit matches, or nothing if no digits match. This repeats in a for loop up to 10 guesses.

Uploaded by

api-469636482
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views2 pages

Lottery

This Java code simulates a lottery game by generating a random two-digit number and prompting the user to guess it. It uses logic to compare the digits of the guessed and randomly generated numbers to determine different prize amounts: the user wins $10,000 for a correct guess, $3,000 if the digits match but are swapped, $100 if any single digit matches, or nothing if no digits match. This repeats in a for loop up to 10 guesses.

Uploaded by

api-469636482
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;
class Main {
public static void main(String[] args) {

int lottery = (int)(Math.random()* 99);


int guess;
Scanner input = new Scanner(System.in);

int lotteryDigit1 = lottery / 10;


int lotteryDigit2 = lottery % 10;

for(int i = 0; i < 10; i++){

System.out.println("Enter a lottery number");


guess = input.nextInt();

int guessDigit1 = guess / 10;


int guessDigit2 = guess % 10;

if(guess == lottery)
System.out.println("you won $10,000");
else if ( guessDigit1 == lotteryDigit2 && guessDigit2 == lotteryDigit1)
System.out.println("you won $3000");
else if(guessDigit1 == lotteryDigit2 || guessDigit2 == lotteryDigit1 || guessDigit1 == lotteryDigit1 ||
guessDigit2 == lotteryDigit2 )
System.out.println("you won $100");
else
System.out.println("your won nothing");

}
}

You might also like