1 import java.util.*; 2 3 class Card 4 { 5 public String num; 6 public String suit; 7 Card(String n,String s) 8 { 9 this.num=n; 10 this.suit=s; 11 } 12 public String toString() 13 { 14 String ss=suit+":"+num+" "; 15 return ss; 16 } 17 } 18 19 class DeskOfCard { 21 Card card[]; 22 public void initcard() { //初始化 24 String num[]={"A","2","3","4","5","6","7","8","9","10","J","Q","K"}; 25 String suit[]={"方块","梅花","红桃","黑桃"}; 26 card = new Card[52]; 27 for(int i=0;i<52;i++) { 29 card[i] = new Card(num[i%13],suit[i/13]); 30 } 31 } 32 33 public void shufflecard() {//洗牌 35 Random rd = new Random(); 36 for(int i=0;i<52;i++) { 38 int j = rd.nextInt(52);//生成随机数 39 Card temp = card[i];//交换 40 card[i]=card[j]; 41 card[j]=temp; 42 } 43 } 44 45 46 public void dealcard( {//发牌 48 for(int i=0;i<52;i++) { 50 if(i%4==0) System.out.println(" "); 51 System.out.print(card[i]); 52 } 53 } 54 } 55 56 public class TestCard { 58 public static void main(String[] args) { 60 DeskOfCard cc = new DeskOfCard(); 61 cc.initcard(); 62 cc.shufflecard(); 63 cc.dealcard(); 64 } 65 }