public class DeckOfCards{
public static void main(String[]args) {
int [] deck =new int [54] ; //规定扑克张数
String[] suits = { "方片" ,"黑桃 " ,"梅花 " ," 红桃" } ;
String [] ranks = {"Ace ","2","3","4","5","6","7","8","9","10","Jack","Queen","King" } ;
for(int i = 0 ; i < deck.length ; i++) // 得到扑克牌的下标
deck[i] =i ;
for( int i =0; i< deck.length ; i++) { // 洗牌
int j = (int) (Math.random() * deck.length ) ;
int temp = deck[i] ; // 把现有的一张牌赋给一个临时值
deck[i] = deck[j]; // 把随机得到的牌赋给现在的牌面
deck[j] = temp ; // 把临时牌面的牌赋值给随机牌面
}
// 下面代码块不在控制牌数循环内
for( int i = 0 ; i < deck.length-1 ; i++) {
String suit = suits[ deck[i] / 13 ] ;
String rank = ranks[ deck[i] % 13 ] ;
if( i>= deck.length-1 )
System.out.print("底牌是: "+ rank+suit );
else if( i % 3==0)
System.out.printf(rank+suit+ " " );
else if(i % 3 == 1 )
System.out.print(" "+ rank+suit );
else if( i % 3 == 2 )
System.out.println(" "+ rank+suit );
}
}
}
@♬晨灬曦 @GTA小鸡 我把程序贴上来了