Review Java collection cases _ Landlords

Some time ago sick, hurry, wrestling, injured ...... blue skinny group of recently has been more than 20 days to review the contents of Java-based, now looking back, I feel much better simply change the code, and also feel every day there is no need to fill in the code on the blog, review today to the collection, I feel this case Landlords also more interesting, take a piece of code on a wave of fun at the code as follows:

. 1  Package com.itheima_02;
 2  
. 3  Import Classes in java.util *. ;
 . 4  
. 5  / ** 
. 6  * landlord shuffling cards analog watch case licensing
 . 7   * / 
. 8  public  class Demo07 {
 . 9      public  static  void main (String [] args ) {
 10  //         analog landlord licensing see case shuffling cards. 1 
. 11          ddz1 ();
 12 is  
13 is      }
 14  
15      Private  static  void ddz1 () {
 16          the while ( to true ) {
 . 17              // do licensing
18             ArrayList<String> box = new ArrayList<>();
19             String[] kind = {"♠", "♥", "♣", "♦"};
20             String[] num = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
21             //裝盒
22             for (String s1 : kind) {
23                 for (String s2 : num) {
24                     box.add(s1 + s2);
25                 }
26             }
27             box.add("joker");
28             box.add("JOKER");
29             //隨機順序洗牌
30             Collections.shuffle(box);
31             //發牌
32             ArrayList<String> player1 = new ArrayList<>();
33             ArrayList<String> player2 = new ArrayList<>();
34             ArrayList<String> player3 = new ArrayList<>();
35             ArrayList<String> bottom = new ArrayList<>();
36             for (int i = 0; i < box.size(); i++) {
37                 String pres = box.get(i);
38                 if (i >= box.size() - 3) {
39                     bottom.add(pres);
40                 } else if (i % 3 == 0) {
41                     player1.add(pres);
42                 } else if (i % 3 == 1) {
43                     player2.add(pres);
44                 } else if (i % 3 == 2) {
45                     player3.add(pres);
46                 }
47             }
48             //看牌
49             check ( "players. 1" , Player1);
 50              check ( "player 2" , player2);
 51 is              check ( "players. 3" , player3);
 52 is              ( "bottom" Check bottom,);
 53 is              System.out.println ( " enter exit to exit, re retransmission input " );
 54 is              Scanner SC = new new Scanner (the System.in);
 55              String S = sc.nextLine ();
 56 is              IF (s.equals (" exit " )) {
 57 is                  System.exit (0 );
 58              } the else  IF (s.equals ( "Re")) {
59                 continue;
60             }
61         }
62     }
63 
64     private static void check(String name, ArrayList<String> box) {
65         System.out.println(name + "牌是:");
66         for (String pres : box) {
67             System.out.print(pres + " ");
68         }
69         System.out.println("\r\n");
70     }
71 }

Here while loop wrapped with a code, after running the program in the console input end exit or enter a re, re-execute the program.

Guess you like

Origin www.cnblogs.com/zzzzzpaul/p/11370034.html