赞
踩
package landlords;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Landlords {
public static void main(String[] args) {
Map<Integer,String> pokers = new HashMap<>();
List list = new ArrayList<>();
String[] colors = {“♥”,“♣”,“♠”,“♦”};
String[] numbers = {“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,“J”,“Q”,“K”,“A”,“2”};
int num = 0;
for(String number : numbers) {
for(String color : colors) {
String poker = color + number;
pokers.put(num, poker);
list.add(num);
num++;
}
}
pokers.put(num, “小王”);
list.add(num++);
pokers.put(num, “大王”);
list.add(num );
System.out.println(“所有的牌:” + pokers);
System.out.println(“牌的编号:” +list);
Collections.shuffle(list);
System.out.println(“洗好牌后,编号为” + list);
List liuyifei = new ArrayList<>();
List zhaoliying = new ArrayList<>();
List xiaohei = new ArrayList<>();
List dipai = new ArrayList<>();
for(int i = 0; i < list.size(); i++ ) {
Integer pokerNum = list.get(i);
if(i >= list.size() - 3) {
dipai.add(pokerNum);
}else if(i % 3 == 0 ) {
liuyifei.add(pokerNum);
}else if(i % 3 == 1 ) {
zhaoliying.add(pokerNum);
}else if(i % 3 == 2 ) {
xiaohei.add(pokerNum);
}
}
// System.out.println(“liuyifei” + liuyifei);
// System.out.println(“zhaoliying” + zhaoliying);
// System.out.println(“xiaohei” + xiaohei);
// System.out.println(“dipai” + dipai);
//
System.out.println("-----------");
System.out.println(“liuyifei” + printPoker(liuyifei,pokers));
System.out.println(“zhaoliying” + printPoker(zhaoliying,pokers));
System.out.println(“xiaohei” + printPoker(xiaohei,pokers));
System.out.println(“dipai” + printPoker(dipai,pokers));
}
public static String printPoker(List nums, Map<Integer,String>pokers) {
**Collections.sort(nums);
StringBuilder sb = new StringBuilder();
for(Integer num : nums) {
String poker = pokers.get(num);
sb.append(poker + " ");
}
String str = sb.toString();
return str.trim();**
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。