Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Chapter 3 Lottery {
- public static void main(String[] args) {
- // Lottery Pick 2
- Scanner input=new Scanner(System.in);
- // generate a random number from 0 to 99 and then extract the digits
- int lottery=(int)(Math.random()*100);
- int lotDigit1=lottery/10; // dividing by 10 extracts the first digit
- int lotDigit2=lottery%10; // lottery has not changed. % by 10 gets you the second digit
- // prompt the user for their guess and get it from the console
- System.out.println("Enter your 2 digit lottery choice: ");
- int yours=input.nextInt();
- int yourDigit1=yours/10; // dividing by 10 extracts the first digit
- int yourDigit2=yours%10; // yours has not changed. % by 10 gets you the second digit
- if (yours==lottery)
- System.out.println("Your number is " +yours+ " and the lottery number is "+lottery+". You win $10,000");
- else if (lotDigit1==yourDigit2 && lotDigit2==yourDigit1)
- System.out.println("Your number is " +yours+ " and the lottery number is "+lottery+". You win $5,000");
- else if (lotDigit1==yourDigit1 ||
- lotDigit1==yourDigit2 ||
- lotDigit2==yourDigit1 ||
- lotDigit2==yourDigit2)
- System.out.println("Your number is " +yours+ " and the lottery number is "+lottery+". You win $1,000");
- else
- System.out.println("Your number is " +yours+ " and the lottery number is "+lottery+". No matches");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement