```
    package com.lushunde.dzpk;

    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    import java.util.Scanner;

    import com.lushunde.dzpk.model.Poker;

    public class MainRun {

    1. public static void main(String[] args) {

    System.out.println(“如下规则介绍:”);
    System.out.println(“ 两个字符代表一张牌,第一个字符SHDC代表花色:黑红方草,第二个字符2-9或者TJQKA代表大小。”);
    System.out.println(“ 输入20个字符,前十个代表第一手牌,后10个代表第二手牌。例如 S2S3S4S5S7D4D9DAD2C4 “);
    System.out.println(“ 输入>代表第一手牌大于第二手牌,<代表小于,=代表平。”);

    System.out.println(“开始输入…”);


    Scanner sc = new Scanner(System.in);
    while (sc.hasNext()) {

    1. String line = sc.next();<br /> if (line == null || line.trim().equals("")) {<br /> } else if (line.equalsIgnoreCase("exit")) {<br /> System.out.println("退出系统");<br /> break;<br /> } else if (line.length() == 20) {<br /> List<Poker> first = new ArrayList<>();<br /> List<Poker> last = new ArrayList<>();<br /> conver(first, last, line);
    2. // 完成排序<br /> System.out.println("第一手牌:" + first);<br /> System.out.println("第二手牌:" + last);<br /> // 比较<br /> comparePoker(first, last);<br /> <br /> <br /> // 提示<br /> System.out.println("请输入下一次比较的数据...");<br /> } else {<br /> System.out.println("输入错误,请重新输入...");<br /> }<br /> }<br /> <br /> sc.close();
    3. }
    4. /**<br /> * 两手牌比较<br /> * <br /> * @param first<br /> * @param last<br /> */
    5. private static void comparePoker(List<Poker> first, List<Poker> last) {<br /> // TODO Auto-generated method stub<br /> int compareTo = first.get(0).compareTo(last.get(0));<br /> <br /> if(compareTo == 0 ){<br /> System.out.println( "=" );<br /> }<br /> if(compareTo > 0 ){<br /> System.out.println( "<" );<br /> }<br /> if(compareTo < 0 ){<br /> System.out.println( ">" );<br /> }<br /> }
    6. /**<br /> * 将line转换为 牌<br /> * <br /> * @param first<br /> * @param last<br /> * @param line<br /> */<br /> private static void conver(List<Poker> first, List<Poker> last, String line) {<br /> // TODO Auto-generated method stub

    for (int i = 0; i < 10; i++) {
    String poker = line.substring(i 2, i 2 + 2);
    if (!poker.matches(“[SHDC].”)) {
    System.out.println(“输入的第” + i + “张牌[“ + poker + “]花色错误,请重新输入…”);
    return;
    }
    if (!poker.matches(“.[23456789TJQKA]”)) {
    System.out.println(“输入的第” + i + “张牌[“ + poker + “]数字错误,请重新输入…”);
    return;
    }

    1. // 添加<br /> if (first.size() < 5) {<br /> if (first.contains(poker)) {<br /> System.out.println("输入的第" + i + "张牌[" + poker + "]重复,请重新输入...");<br /> return;<br /> } else {<br /> first.add(new Poker(poker));<br /> }<br /> } else {<br /> if (first.contains(poker) || last.contains(poker)) {<br /> System.out.println("输入的第" + i + "张牌[" + poker + "]重复,请重新输入...");<br /> return;<br /> } else {<br /> last.add(new Poker(poker));<br /> }<br /> }

    }

    // 排序
    Collections.sort(first);
    Collections.sort(last);

    1. }

    }

    ```
    package com.lushunde.dzpk.model;

    public class Poker implements Comparable {

    1. private String poker ;<br /> private Integer decor ;<br /> private Integer value ;
    2. public Poker(String poker) {<br /> super();<br /> this.poker = poker;<br /> this.decor = getDecorInt(poker.substring(0,1));<br /> this.value = getValueInt(poker.substring(1,2));<br /> }
    3. //SHDC代表花色:黑红方草<br /> private Integer getDecorInt(String num) {<br /> if(num.equals("S")){<br /> return 4;<br /> }else if(num.equals("H")){<br /> <br /> return 3;<br /> }else if(num.equals("D")){<br /> <br /> return 2;<br /> }else if(num.equals("C")){<br /> <br /> return 1;<br /> <br /> }else{<br /> throw new RuntimeException("数据不正确");<br /> }<br /> }
    4. private Integer getValueInt(String num) {<br /> if(num.matches("[23456789]")){<br /> return Integer.valueOf(num);<br /> }else if(num.equals("T")){<br /> return 10;<br /> }else if(num.equals("J")){<br /> <br /> return 11;<br /> }else if(num.equals("Q")){<br /> <br /> return 12;<br /> }else if(num.equals("K")){<br /> <br /> return 13;<br /> }else if(num.equals("A")){<br /> return 14;<br /> }else{<br /> throw new RuntimeException("数据不正确");<br /> }<br /> }<br /> public String getPoker() {<br /> return poker;<br /> }<br /> public void setPoker(String poker) {<br /> this.poker = poker;<br /> }
    5. public Integer getDecor() {<br /> return decor;<br /> }
    6. public Integer getValue() {<br /> return value;<br /> }

    // @Override
    // public int compare(Poke o1, Poke o2) {
    // return (o1.getValue().compareTo(o2.getValue())!=0)? (o1.getValue().compareTo(o2.getValue())): (o1.getDecor().compareTo(o2.getDecor())) ;
    // }

    1. @Override<br /> public String toString() {<br /> return "Poke [poker=" + poker + "]";<br /> }
    2. @Override<br /> public int compareTo(Poker o) {<br /> return (o.getValue().compareTo(this.getValue())!=0)? (o.getValue().compareTo(this.getValue())): (o.getDecor().compareTo(this.getDecor())) ;<br /> <br /> }

    }