题目
模拟从一副扑克牌52张中选择一张。程序中牌的大小应显示为(Ace,1,2,3,4,5,6,7,8,9,10,Jack,Queen,King),牌的花色应该显示为(Diamonds(方块),Hearts(红心),Spades(黑桃),Clubs(梅花))。程序某一次运行时的输出如下:
The Card you picked is Jack of Hearts.
Java代码
/**
* @author lmh
*
* @version 2020年11月8日
*/
import java.util.Random;
public class Poker {
public static void main(String [] args){
String []num = {"Ace","1","2","3","4","5",
"6","7","8","9","10","Jack","Queen","King"};
String []colors = {"Diamonds","Hearts","Spades","Clubs"};
Random random=new Random();//以系统当前时间作为随机数生成的种子
int c = (int)(random.nextInt(4));//返回一个大于等于0且小于4的整数
int n = (int)(random.nextInt(14));//返回一个大于等于0且小于14的整数
System.out.println("The Card you picked is " + num[n] + " of " +colors[c]+".");
}
}