当前位置:   article > 正文

玩扑克牌的代码_男生和女生打卜克

男生和女生打卜克

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);
}

}
  • 1

// 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();**
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

}
}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/422179
推荐阅读
相关标签
  

闽ICP备14008679号