彩票
1 package test; 2 3 import java.util.Scanner; 4 5 public class Lottery { 6 7 public static void main(String[] args) { 8 // TODO Auto-generated method stub 9 10 int lottery = (int)(Math.random()*100); 11 12 Scanner input = new Scanner(System.in); 13 System.out.print("Enter your lottery pick (two digits):"); 14 int guess = input.nextInt(); 15 16 int lotteryDigit1 = lottery/10; 17 int lotteryDigit2 = lottery%10; 18 19 int guessDigit1 = guess/10; 20 int guessDigit2 = guess%10; 21 22 System.out.println("The lottery number is " + lottery); 23 24 if(guess==lottery) 25 System.out.println("Exact match : youwin $10,000"); 26 else if (guessDigit2 == lotteryDigit1 27 && guessDigit1 == lotteryDigit2) 28 System.out.println("Match all digits:you win $3.000"); 29 else if (guessDigit1 == lotteryDigit1 30 || guessDigit1 == lotteryDigit2 31 || guessDigit2 == lotteryDigit1 32 || guessDigit2 == lotteryDigit2) 33 System.out.println("Match one digit: you win $1.000"); 34 else 35 System.out.println("Sorry,no match"); 36 37 } 38 39 }