今天讲的 问题 死活想不明白求解 我打印mapping的时候 少一个2 求解
private static int key =0;
public static void main(String[] args) {
//找数字扑克和 扑克的对应关系 key-->poker value-->扑克
Map<Integer, String> mapping = new HashMap<>();
//集合装扑克牌
ArrayList<Integer> poker = new ArrayList<Integer>();
for(int i=1;i<=54;i++){
poker.add(i);
}
//组装扑克
//扑克颜色
ArrayList<String> color = new ArrayList<String>();
Collections.addAll(color, "♠","♥","♦","♣");
//扑克数字
ArrayList<String> number = new ArrayList<String>();
for (int i = 3; i <11 ; i++) {
number.add(""+i);
}
Collections.addAll(number, "J","Q","K","A","2");
//组合扑克
Integer thisKey =0;
System.out.println(poker.size());
for (String thisNumber : number) {
for (String thisColor : color) {
for(;key<poker.size();){ //从0- 53 poker.size()=54
thisKey=poker.get(key);
String thisValue = thisColor+thisNumber;
mapping.put(thisKey, thisValue);
key++;
break;
}
}
}
mapping.put(key++,"小☺");
mapping.put(key,"大☻");
System.out.println(mapping);
|
|