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);
}
}
}
标签:case,return,斗地主,int,碎片,new,Java,public
From: https://www.cnblogs.com/wzztabaorz/p/18527132