初学Java 彩票
1 import java.util.Scanner; 2 3 public class Lottery { 4 public static void main(String[] agrs) { 5 int lottery = (int)(Math.random() * 100); 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 lotteryDigit1 = lottery / 10; 12 int lotteryDigit2 = lottery % 10; 13 14 int guessDigit1 = guess / 10; 15 int guessDigit2 = guess % 10; 16 17 System.out.println("The lottery number is " + lottery); 18 19 if (guess == lottery) 20 System.out.println("exact match: you win $10000"); 21 else if (guessDigit2 == lotteryDigit1 22 && guessDigit1 == lotteryDigit2) 23 System.out.println("Math all digits: you win $3000"); 24 else if (guessDigit1 == lotteryDigit1 25 || guessDigit1 == lotteryDigit2 26 || guessDigit2 == lotteryDigit1 27 || guessDigit2 == lotteryDigit2) 28 System.out.println("Match one digit: you win $1000"); 29 else 30 System.out.println("Sorry, no macth"); 31 } 32 }