标签:
1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter your lottery pick (two digits): "); 9 int guess = input.nextInt(); 10 11 int lottery = (int)(Math.random() * 100); 12 int lotteryDigit1 = lottery / 10; 13 int lotteryDigit2 = lottery % 10; 14 15 while(lotteryDigit1 == lotteryDigit2) 16 { 17 lottery = (int)(Math.random() * 100); 18 lotteryDigit1 = lottery / 10; 19 lotteryDigit2 = lottery % 10; 20 } 21 22 int guessDigit1 = guess / 10; 23 int guessDigit2 = guess % 10; 24 25 System.out.println("The lottery number is " + lottery); 26 27 if(guess == lottery) 28 System.out.println("Exact match: you win $10,000"); 29 else if(guessDigit2 == lotteryDigit1 && guessDigit1 == lotteryDigit2) 30 System.out.println("Match all digits: you win $3,000"); 31 else if(guessDigit1 == lotteryDigit1 || guessDigit1 == lotteryDigit2 || 32 guessDigit2 == lotteryDigit2 || guessDigit2 == lotteryDigit1) 33 System.out.println("Match one digit: you win $1,000"); 34 else 35 System.out.println("Sorry, no match"); 36 } 37 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5785946.html