扑克牌
package com.oracle.demo01; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map; public class Demo01 { public static void main(String[] args) { // 创建容器 Map<Integer, String> pooker=new HashMap<Integer, String>(); ArrayList<Integer> pookerNumder =new ArrayList<>(); // 封装数据 String[] color={"♥","♠","♦","♣"}; String[] numder={"2","A","K","Q","J","10","9","8","7","6","5","4","3"}; int index=2; for(String n:numder){ for(String c:color){ pooker.put(index,c+n); pookerNumder.add(index); index++; } } pooker.put(0, "大王"); pooker.put(1, "小王"); pookerNumder.add(0); pookerNumder.add(1); // 洗牌 Collections.shuffle(pookerNumder); // 发牌 ArrayList<Integer> p1=new ArrayList<Integer>(); ArrayList<Integer> p2=new ArrayList<Integer>(); ArrayList<Integer> p3=new ArrayList<Integer>(); ArrayList<Integer> bottom=new ArrayList<Integer>(); for(int i=0;i<pookerNumder.size();i++){ if(i<3){ bottom.add(pookerNumder.get(i)); }else if(i%3==0){ p1.add(pookerNumder.get(i)); }else if(i%3==1){ p2.add(pookerNumder.get(i)); }else if(i%3==2){ p3.add(pookerNumder.get(i)); } } // 排序 Collections.sort(bottom); Collections.sort(p1); Collections.sort(p2); Collections.sort(p3); look( "李四",pooker,p1); look("王五",pooker,p2); look("王五",pooker,p3); look("王五",pooker,bottom); } // 看牌方法 public static void look(String name,Map<Integer, String> pooker,ArrayList<Integer>player) { System.out.print(name+":"); for(int key:player){ System.out.print(pooker.get(key)+" "); } System.out.println(); } }