异常(8.9)

今天讲了斗地主排序程序、异常处理;

斗地主排序代码:
import java.util.*;

public class pukepaipx {
public static void main(String[] args){
Map<Integer,String> pokers=new HashMap<>();
String[] colors=new String[]{“黑桃”,“红桃”,“方块”,“梅花”};
String[] numbers=new String[]{“A”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,“J”,“Q”,“K”};
int index=1;
for(String color:colors){
for(String num:numbers){
String pai=color+num;
pokers.put(index,pai);
index++;
}
}
pokers.put(index,“小王”);
index++;
pokers.put(index,“大王”);
System.out.println(pokers);

    List<Integer> pokerIndexs=new ArrayList<>();
    for(Integer i:pokers.keySet()){
        pokerIndexs.add(i);
    }
    System.out.println(pokerIndexs);
    //2.洗牌
    Collections.shuffle(pokerIndexs);
    System.out.println(pokerIndexs);
    //3.留三张底牌
    pokerIndexs.remove(0);
    pokerIndexs.remove(0);
    pokerIndexs.remove(0);

    System.out.println(pokerIndexs);

    //List 有序 可重复 Set 无序 不可重复
    Set<Integer> linxiangtao=new TreeSet<>();
    Set<Integer> hualili=new TreeSet<>();
    Set<Integer> jiangxinwei=new TreeSet<>();

    for(int i=0;i<pokerIndexs.size();i++){
       int pokerIndex=pokerIndexs.get(i);
       int mod=i%3;
       if(mod==0){
           linxiangtao.add(pokerIndex);
       }else if(mod==1){
           hualili.add(pokerIndex);
       }else{
           jiangxinwei.add(pokerIndex);
       }
       }
       System.out.println("linxiangtao:"+linxiangtao);
       System.out.println("hualili:"+hualili);
       System.out.println("jiangxinwei:"+jiangxinwei);
       look(pokers,linxiangtao);
       look(pokers,hualili);
       look(pokers,jiangxinwei);
    }

public static void look(Map<Integer, String> pokers, Set<Integer> playerPokerIndexs) {
    List<String> pokerValues=new ArrayList<>();
    for(Integer index:playerPokerIndexs){
        pokerValues.add(pokers.get(index));

    }
    System.out.println(pokerValues);
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值