public class PokePai {
//定义一个静态集合
public static ArrayList<String> cards = new ArrayList<>();
//静态代码块
static {
String[] sizes= {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
String[] colors={"♥","♣","♠","♦"};
//遍历点数
for (int i = 0; i < sizes.length; i++) {
//遍历花色
for (int j = 0; j < colors.length; j++) {
String card = sizes[i]+colors[j];
cards.add(card);
}
}
cards.add("大王牌");
cards.add("小王牌");
}
public static void main(String[] args) {
System.out.println("新牌:" + cards);
}
}
使用静态代码块生成一副扑克牌
于 2022-09-15 22:53:04 首次发布