Advertisement
therrontelford

Lottery

Nov 12th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import java.util.*;
  2. public class Chapter 3 Lottery {
  3.  
  4.     public static void main(String[] args) {
  5.         // Lottery Pick 2
  6.         Scanner input=new Scanner(System.in);
  7.  
  8.         // generate a random number from 0 to 99 and then extract the digits
  9.         int lottery=(int)(Math.random()*100);
  10.         int lotDigit1=lottery/10;   // dividing by 10 extracts the first digit
  11.         int lotDigit2=lottery%10;   // lottery has not changed.  % by 10 gets you the second digit
  12.  
  13.         // prompt the user for their guess and get it from the console     
  14.         System.out.println("Enter your 2 digit lottery choice: ");
  15.         int yours=input.nextInt();
  16.         int yourDigit1=yours/10;    // dividing by 10 extracts the first digit
  17.         int yourDigit2=yours%10;    // yours has not changed.  % by 10 gets you the second digit
  18.        
  19.         if (yours==lottery)
  20.             System.out.println("Your number is " +yours+ " and the lottery number is "+lottery+". You win $10,000");
  21.         else if (lotDigit1==yourDigit2 && lotDigit2==yourDigit1)
  22.             System.out.println("Your number is " +yours+ " and the lottery number is "+lottery+". You win $5,000");
  23.         else if (lotDigit1==yourDigit1 ||
  24.                 lotDigit1==yourDigit2 ||
  25.                 lotDigit2==yourDigit1 ||
  26.                 lotDigit2==yourDigit2)
  27.                 System.out.println("Your number is " +yours+ " and the lottery number is "+lottery+". You win $1,000");
  28.         else
  29.             System.out.println("Your number is " +yours+ " and the lottery number is "+lottery+".  No matches");
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement