문자열 은 수치 크기 비교 입 니 다.

/**
*         ,               (   3-10,          )
*
*  String[] nums = ...  ,   3-9  03-09,     "9" > "10",  
*      (  )       10   ,  10     。
*
*  :                 ,3-9     ,  10    ,Java 
*  "10" "9"    ,∵ 1 < 9, ∴ 10 < 9
*
*@author Prannt
*
*/
import java.util.ArrayList;
import java.util.Collections;

public class DouDiZhu {
     
    public static void main(String[] args) {
     
        //1.   ,      54     
        ArrayList <String> poker = new ArrayList<>();
        //      ,          ,           
        String [] colors = {
     "♠","♥","♣","♦"};
        String [] nums = {
     "03","04","05","06","07","08","09","10","J","Q","K","A","2"};
        //          poker   
        poker.add("  ");
        poker.add("  ");
        //          ,  52  
        for(String num : nums){
     
            for (String color : colors) {
      //   :colors.for
                //System.out.print((num + color) + " ");
                //         poker   
                poker.add(num + color);
            }
        }
        //System.out.println(poker);

        //2.  
        Collections.shuffle(poker);
        //System.out.println(poker);

        //3.  。      ,         
        ArrayList <String> player01 = new ArrayList<>();
        ArrayList <String> player02 = new ArrayList<>();
        ArrayList <String> player03 = new ArrayList<>();
        ArrayList <String> diPai = new ArrayList<>();

        //  poker  ,      
        for (int i = 0; i < poker.size(); i++) {
     
            String s = poker.get(i);
            if(i >= 51) {
     
                //     
                diPai.add(s);
                Collections.sort(diPai); //      
            } else if(i % 3 == 0) {
     
                player01.add(s);
                Collections.sort(player01);
            } else if(i % 3 == 1) {
     
                player02.add(s);
                Collections.sort(player02);
            } else if(i % 3 == 2) {
     
                player03.add(s);
                Collections.sort(player03);
            }
        }
        System.out.println(player01);
        System.out.println(player02);
        System.out.println(player03);
        System.out.println(diPai);
    }
}

/*   3-9    03-09,        (   3-10          ):
[10♥, 2♣, 2♦, 3♠, 5♥, 6♣, 6♦, 7♣, 7♦, 8♥, 9♥, 9♦, A♠, A♣, J♥, K♠, Q♦]
[10♠, 2♥, 3♣, 3♥, 4♥, 5♠, 6♥, 7♥, 8♠, 8♦, 9♠, J♠, J♣, J♦, K♣, Q♠, Q♣]
[10♣, 10♦, 2♠, 3♦, 4♠, 4♣, 4♦, 5♣, 6♠, 7♠, 8♣, 9♣, A♥, A♦, Q♥,   ,   ]
[5♦, K♥, K♦]
*/

/*  3-9    03-09,        (   3-10          ):
[03♣, 03♥, 03♦, 04♣, 05♣, 06♣, 06♥, 06♦, 07♠, 08♣, 08♦, 2♣, 2♦, A♠, A♦, J♥, Q♥]
[03♠, 04♠, 04♥, 05♠, 05♦, 07♦, 08♠, 08♥, 09♠, 09♣, 09♦, 10♠, A♥, Q♠, Q♦,   ,   ]
[04♦, 05♥, 06♠, 07♣, 07♥, 09♥, 10♣, 10♥, 2♠, 2♥, A♣, J♣, J♦, K♠, K♣, K♥, K♦]
[10♦, J♠, Q♣]
*/

좋은 웹페이지 즐겨찾기