/**
* 模拟股神洗牌 1. 52张牌 2. 4种花 13种牌号
*
* @author Administrator
*
*/
public class Shuffle {
public static void main(String[] args) {
int[] cards = new int[52];
String[] color = { "红桃", "黑桃", "方块", "梅花" };
String[] num = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
for (int i = 0; i < cards.length; i++) {
cards[i] = i;
}
for (int j = 0; j < cards.length; j++) {
System.out.printf("%s-%s\t", color[j / 13], num[j % 13]);
if ((j + 1) % 13 == 0) {
System.out.println();
}
}
System.out.println("--------------------------------------------------------");
for (int i = 0; i < cards.length; i++) {
int ramIndex = (int) (Math.random() * 52);
int temp = cards[i];
cards[i] = cards[ramIndex];
cards[ramIndex] = temp;
}
for (int j = 0; j < cards.length; j++) {
System.out.printf("%s-%s\t", color[cards[j] / 13], num[cards[j] % 13]);
if ((j + 1) % 13 == 0) {
System.out.println();
}
}
}
}
java模拟赌神洗牌代码
猜你喜欢
转载自blog.csdn.net/shui_jin_shan/article/details/84074673
今日推荐
周排行