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

HW6.24

时间:2016-08-28 15:04:20      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

技术分享

 

 1 public class Solution
 2 {
 3     public static void main(String[] args)
 4     {
 5         int count = 0;
 6         int color;
 7         int number;
 8         String colorStr;
 9         String numberStr;
10         String[] colorSet = {" ", " ", " ", " "};
11         while(true)
12         {
13             color = (int)(Math.random() * 4);
14             number = (int)(Math.random() * 13);
15 
16             colorStr = getColor(color);
17             numberStr = getNumber(number);
18 
19             System.out.println(numberStr + " of " + colorStr);
20 
21             count++;
22 
23             if(!contains(colorSet, colorStr))
24                 add(colorSet, colorStr);
25 
26             if(isFull(colorSet))
27                 break;
28         }
29 
30         System.out.println("Number of picks: " + count);
31     }
32 
33     public static boolean isFull(String[] array)
34     {
35         for(String str: array)
36             if(str == " ")
37                 return false;
38         return true;
39     }
40 
41     public static boolean contains(String[] array, String str)
42     {
43         for(String i: array)
44             if(i == str)
45                 return true;
46         return false;
47     }
48 
49     public static void add(String[] array, String str)
50     {
51         for(int i = 0; i < array.length; i++)
52             if(array[i] == " ")
53                 array[i] = str;
54     }
55 
56     public static String getColor(int n)
57     {
58         if(n == 0)
59             return "Spades";
60         else if(n == 1)
61             return "Clubs";
62         else if(n == 2)
63             return "Hearts";
64         else
65             return "Diamonds";
66     }
67 
68     public static String getNumber(int n)
69     {
70         if(n == 0)
71             return "King";
72         else if(n == 1)
73             return "Ace";
74         else if(n == 11)
75             return "Jack";
76         else if(n == 12)
77             return "Queen";
78         else
79             return "" + n;
80     }
81 }

 

HW6.24

标签:

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

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