首页 > 试题广场 >

( 游戏:挑一张牌)编写程序,模拟从一副 S2 张的牌中选

[问答题]
 ( 游戏:挑一张牌)编写程序,模拟从一副 S2 张的牌中选择一张牌。程序应该显示牌的大小 (Ace、2、3、4、5、6、7、8、9、10、Jack、Queen、King)以及牌的花色(Clubs (黑梅花)、 Diamonds (红方块) 、Hearts (红心) 、Spades (黑桃))。下面是这个程序的运行示例:


    public static void main(String[] args) {
        String[] size = new String[]{"Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};  
        String[] suit = new String[]{"Clubs","Diamonds","Hearts","Spades"};
        int index = (int)(Math.random() *13); 
        int flag= (int)(Math.random() *4); 
        System.out.println("The card you pick is " + size[index] + " of " + suit[flag]);
    }
发表于 2021-05-04 18:39:33 回复(0)