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