一副扑克除去大小王 可以用花色和大小来表示
花色为{红桃,黑桃,草花,方块}
大小为{A,2,3,.....K}请设计一个程序,
(1)能将扑克按照红桃A--红桃K,黑桃A-黑桃K,梅花A-梅花K,方块A-方块K 顺序排列并输出
(2)模仿洗牌程序,将排列好的扑克打乱输出用JAVA语言进行设计 求高人指点,(1)我的思想是建立2个数组,一个表示花色,一个表示大小。在新建立一个新数组,是另外两个数组的元素能交叉生成新元素,具体代码怎么实现?(2)洗牌程序使用随机数进行选择,生成的元素进行重复判断,然后输出,
这个代码也是没有写明白
求大人指教~~

解决方案 »

  1.   

    String[] color = new String[]{"红桃","黑桃","草花","方块"};
    String[] num = new String[]{"A","2","3",....."K"};String[] card = new String[color.length * num.length];
    for(int i = 0; i < color.length; i++)
      for(int j = 0; j < num.length; j++)
        card[i * num.length + j] = color[i] + num[j];
    outputCard(card);
    java.util.Collections.shuffle(card);
    outputCard(card);
      

  2.   

    public static void main(String[] args) throws Exception {
    String[] color = new String[]{"红桃","黑桃","草花","方块"};
    String[] num = new String[]{"A","2","3","4","5","6","7","8","9","J","Q","K"}; ArrayList card = new ArrayList(color.length * num.length);
    for(int i = 0; i < color.length; i++)
      for(int j = 0; j < num.length; j++)
        card.add(color[i] + num[j]);
    outputCard(card);
    java.util.Collections.shuffle(card);
    outputCard(card);
    } private static void outputCard(ArrayList card) {
    for(int i = 0; i < card.size(); i++)
    System.out.print(card.get(i) + ",");
    System.out.println();
    }