思路

实现1

代码

package Powke;
import java.util.ArrayList;
import java.util.Collections;
public class Powke {
public static void main(String[] args) {
	//定义花色与数字
	String[] powkeNum= {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
	String[] powkeColor= {"红桃","黑桃","梅花","方块"};
	//定义扑克
	ArrayList<String> powke=new ArrayList<>(); 
//		for(int i=0;i<powkeColor.length;i++) {
//			for(int j=0;j<powkeNum.length;j++) {
//				powke.add(powkeColor[i] + powkeNum[j]);
//			}		
//		}
	//生成扑克
	for (String color: powkeColor) {
		for (String num:powkeNum) {
			powke.add(color+num);
		}
	}
	//加上大小王
		powke.add("大王");
		powke.add("小王");
		System.out.println("新牌:  "+powke+"\n");//查看新扑克
			
		//洗牌
		Collections.shuffle(powke);
		System.out.println("洗牌: "+powke+"\n");//查看洗过的牌的顺序

		//定义三个牌鬼和底牌接收
		ArrayList<String> under=new ArrayList<>();		
		ArrayList<String> china=new ArrayList<>();		
		ArrayList<String> america=new ArrayList<>();		
		ArrayList<String> russia=new ArrayList<>();
		//发牌
		for(int i=0;i<powke.size();i++) {
			if (i>=(powke.size()-3)) {
				under.add(powke.get(i));
			}
			else if (i%3==0) {
				china.add(powke.get(i));
			}
			else if (i%3==1) {
				america.add(powke.get(i));
			}
			else {
				russia.add(powke.get(i));
			}
			}
		//查看底牌和三个牌鬼的牌
		System.out.println("底牌:  "+under+"\n");
		System.out.println("中国:  "+china+"\n");
		System.out.println("美国:  "+america+"\n");
		System.out.println("苏联:  "+russia+"\n");
}
}

实现2

代码

package powke1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;

public class powke1 {

public static void main(String[] args) {
	String[] powkeNum= {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
	String[] powkeColor= {"红桃","黑桃","梅花","方块"};
		
	HashMap<Integer,String> powke=new HashMap<>();
	ArrayList<Integer> indexList=new ArrayList<>();
	int index=0;
	for (String color:powkeColor) {
		for(String num:powkeNum) {
			powke.put(index, color+num);
			indexList.add(index);
			index++;
		}
	}
	powke.put(index, "大王");
	indexList.add(index++);
	powke.put(index, "小王");
	indexList.add(index);

		
	Collections.shuffle(indexList);
		
	TreeSet<Integer> under=new TreeSet<>();
	TreeSet<Integer> china=new TreeSet<>();
	TreeSet<Integer> russia=new TreeSet<>();
	TreeSet<Integer> america=new TreeSet<>();
		
	for(int i=0;i<indexList.size();i++) {
		if (i>=indexList.size()-3) {
			under.add(indexList.get(i));
		}else if (i%3==0) {
			china.add(indexList.get(i));
		}else if(i%3==1) {
			russia.add(indexList.get(i));
		}else {
			america.add(indexList.get(i));
		}
  			
	}				
	check(powke, under,"底牌");
	check(powke, china,"中国");
	check(powke, russia,"苏联");
	check(powke, america,"美国");
}

private static void check(HashMap<Integer, String> powke, TreeSet<Integer> tg, String name) {
	System.out.println(name+": ");
	for (int key:tg) {
		System.out.print(powke.get(key)+" ");
	}System.out.println("\n");
}
 }