package practice.people.apple;标签:并打印,index,Java,String,deck,int,---,++,length From: https://blog.51cto.com/u_15943742/6129641
import java.util.Random;
public class DeckOfCards {
public static void main(String[] args) {
int deck[] = new int[52];
String[] suits = {"黑桃","红桃","方块","梅花"};
String[] ranks = {"A","2","3","4","5","6","7","8","9","J","Q","K"};
//初始化每张牌
for(int i = 0;i < deck.length; i++) {
deck[i] = i;
}
//打乱牌次序
for(int i = 0;i < deck.length; i++) {
//随机产生一个元素下标0-51
int index = (int)(Math.random()*deck.length);
int temp = deck[i];
deck[i] = deck[index];
deck[index] = temp;
}
for(int i = 0;i < 4; i++) {
String suit = suits[deck[i]/13];
String rank = ranks[deck[i]%13];
System.out.println(suit+" "+rank);
}
}
}