1.從52張撲克牌中隨機抽5張牌
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
/**
*
* @author Ankiia
*/
import java.util.*;
public class Main4 {
public static void main(String[] args){
Random r=new Random();
int a[]=new int[53];
int b[]=new int[5];
int k=0;
for(int i=0;i<5;i++){
k=1+r.nextInt(52);
if(a[k]==1){
i--;
continue;
}
else{
b[i]=k;
a[k]=1;
}
}
for(int i=0;i<5;i++){
if(b[i]/13==0){
System.out.print("梅花");
}else if(b[i]/13==1){
System.out.print("方塊");
}else if(b[i]/13==2){
System.out.print("黑桃");
}else if(b[i]/13>=3){
System.out.print("紅心");
}
System.out.print(trans(b[i]%13)+"\t");
}
}
public static char trans(int k){
switch (k){
case 1:
return 'A';
case 11:
return 'J';
case 12:
return 'Q';
case 0:
return 'K';
default:
return (char)(k+48);
}
}
}