码迷,mamicode.com
首页 > 其他好文 > 详细

HW4.32

时间:2016-08-19 00:56:06      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 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 }

 

HW4.32

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5785946.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!