思路告诉你:定义一个数组,存入值。
计算出size,Math.random生成一个下标(范围从0到size),get(index)取出值,再计算size,循环

解决方案 »

  1.   

    Collections.shuffle(list) 然后remove 
      

  2.   

    import java.util.Random;public class HelloRandom {

    public static void main(String Args[]){

    String[] hs = new String[]{"红桃","黑桃","方片","梅花"};
    String[] pm = new String[]{"Ace","2","3","4","5","6","7","8","9","10","J","Q","K"};

    String pk1="";
    String pk2="";
    String pk3="";

    Random rand = new Random();

    pk1 = hs[rand.nextInt(4)]+pm[rand.nextInt(13)];

    while ("".equals(pk2) || pk2.equals(pk1)){
    pk2 = hs[rand.nextInt(4)]+pm[rand.nextInt(13)];
    }

    while ("".equals(pk3) || pk3.equals(pk2) || pk3.equals(pk1)){
    pk3 = hs[rand.nextInt(4)]+pm[rand.nextInt(13)];
    }

    System.out.println("扑克为:"+pk1+" "+pk2+" "+pk3);

    }
    }
      

  3.   

    不知道对不。List<String> list = new ArrayList<String>();
    String[] values = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J","Q", "K", "A" };
    int temp1=0,temp2=0;
    for (int i = 0; i < values.length; i++) {
    temp1=i+1;
    while(temp1<values.length){
    temp2=temp1+1;
    while(temp2<values.length){
    list.add(values[i]+"-->"+values[temp1]+"-->"+values[temp2]);
    temp2++;
    }
    temp1++;
    }
    }

    int count=0;
    String[] str =null;
    String[] colors = {"红桃", "黑桃", "方块", "梅花" };
    for (int i = 0; i < list.size(); i++) {
    str =list.get(i).split("-->");
    for (String c0 : colors) {
    for (String c1: colors) {
    for (String c2: colors) {
    count++;
    System.out.println(c0+str[0]+"-->"+c1+str[1]+"-->"+c2+str[2]);
    }
    }
    }
    }
    System.out.println("count-->"+count);
      

  4.   

    public static void printAll() {
    int count = 0;
    for (int i = 0; i < 50; i++) {
    for (int j = i + 1; j < 51; j++) {
    for (int k = j + 1; k < 52; k++) {
    count++;
    System.out.println(getName(i) + "  " 
    + getName(j) + "  " + getName(k));
    }
    }
    }

    System.out.println("Total: " + count);
    }

    public static String getName(int i) {
    final String[] cards = {"A", "2", "3", "4", "5", "6", "7", 
    "8", "9", "10", "J", "Q", "K"};
    final String[] suits = {"Spade ", "Heart ", "Club ", "Diamond "};

    return suits[i / 13] + cards[i % 13];
    }
      

  5.   

    rui888 大哥,这个我编译不了!
      

  6.   


    您好。这个用什么主类。
    随便什么主类啊,你只要在main函数里调用printAll就行了
      

  7.   


    您好。这个用什么主类。
    随便什么主类啊,你只要在main函数里调用printAll就行了
    大哥,我换成main方法就ok了.能否帮我注释一下,感激不尽!
      

  8.   

    public enum Huase {
    HEITAO("黑桃"), HONGXIN("红心"), MEIHUA("梅花"), FANGKUAI("方块");

    private Huase(String c){
    this.c = c;
    }

    private String c;

    public String getC() {
    return c;
    }

    }
    public enum Daxiao {
    ONE("A"), TWO("2"), THREE("3"), FOUR("4"), FIVE("5"), 
    SIX("6"), SEVEN("7"), EIGHT("8"), NINE("9"), TEN("10"), 
    JOKER("J"), QUEUE("Q"), KING("K");

    private Daxiao(String c){
    this.c = c;
    }

    private String c;

    public String getC(){
    return c;
    }
    }
    public class Pai {
    private Huase huase;
    private Daxiao daxiao;

    public Pai(Huase huase, Daxiao daxiao) {
    super();
    this.huase = huase;
    this.daxiao = daxiao;
    }
    public Huase getHuase() {
    return huase;
    }
    public void setHuase(Huase huase) {
    this.huase = huase;
    }
    public Daxiao getDaxiao() {
    return daxiao;
    }
    public void setDaxiao(Daxiao daxiao) {
    this.daxiao = daxiao;
    }
    @Override
    public String toString() {
    return "Pai [" + huase.getC() + daxiao.getC() + "]";
    }

    }
    import java.util.ArrayList;
    import java.util.List;public class YiFuPai {
    private List<Pai> list = new ArrayList<Pai>();
    public YiFuPai(){
    for(Huase huase : Huase.values()){
    for(Daxiao daxiao : Daxiao.values()){
    list.add(new Pai(huase, daxiao));
    }
    }
    }
    public void getThreePais(){
    int count = 1;
    for(int i=0; i<list.size(); i++){
    for(int j=i+1; j<list.size(); j++){
    for(int k=j+1; k<list.size(); k++){
    System.out.print(count++);
    System.out.print("----");
    System.out.println(
    list.get(i).toString() + 
    list.get(j).toString() + 
    list.get(k).toString());
    }
    }
    }
    }
    public static void main(String[] args) {
    YiFuPai yifupai = new YiFuPai();
    yifupai.getThreePais();
    }
    } 22100条   不知道对不对
      

  9.   


    package mytest.test0609;import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;public class Test {
    public static void main(String[] args) {
    String[] ps = get52Pai();
    List<String> list = new ArrayList<String>();
    for (int i = 0; i < ps.length - 2; i++) {
    String[] ss = new String[3];
    ss[0] = ps[i];
    for (int j = i + 1; j < ps.length - 1; j++) {
    ss[1] = ps[j];
    for (int k = j + 1; k < ps.length; k++) {
    ss[2] = ps[k];
    list.add(Arrays.toString(ss));
    }
    }
    }
    for (int i = 0; i < list.size(); i++) {
    System.out.println(list.get(i));
    }
    System.out.println(list.size());// 22100
    } public static String[] get52Pai() {
    String[] hss = { "红桃", "方块", "梅花", "黑桃" };
    String[] szs = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2" };
    String[] ps = new String[52];
    int i = 0;
    for (String sz : szs) {
    for (String hs : hss) {
    ps[i++] = hs + sz;
    }
    }
    return ps;
    } public static String[] get54Pai() {
    String[] hss = { "红桃", "方块", "梅花", "黑桃" };
    String[] szs = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2" };
    String[] ws = { "小王", "大王" };
    String[] ps = new String[54];
    int i = 0;
    for (String sz : szs) {
    for (String hs : hss) {
    ps[i++] = hs + sz;
    }
    }
    ps[52] = ws[0];
    ps[53] = ws[1];
    return ps;
    }
    }
      

  10.   

    对的,您真厉害,非常感谢,惭愧的说,没怎么看懂....目前就vnvlyp大哥的代码研究出了点头绪!
      

  11.   

    public static String getName(int i) {
        final String[] cards = {"A", "2", "3", "4", "5", "6", "7", 
                "8", "9", "10", "J", "Q", "K"};
        final String[] suits = {"♠ ", "♥ ", "♣ ", "♦ "};
         
        return suits[i / 13] + cards[i % 13];
    @vnvlyp  您的这一段没懂....请教请教...
      

  12.   


    我是用0~51来表示每张扑克牌,分成四组0~12,13~25,26~38,39~51,没别表示四个花色,每一组中13个数,分别表示同花色13张牌,所以/4得到分组,也就是花色,而%13得到具体是哪一张牌。
    分别表示四个花色,打错了
    嗯嗯 有道理.大哥.final 的特性是....
      

  13.   

    int count = 0;
        for (int i = 0; i < 50; i++) {
            for (int j = i + 1; j < 51; j++) {
                for (int k = j + 1; k < 52; k++) {
                    count++;
                    System.out.println(getName(i) + "  " 
                            + getName(j) + "  " + getName(k));
                }
            }
        }
         
        System.out.println("Total: " + count);
    您好大哥,这里count 怎么取到这个三层循环的结果的,.....我太笨了!
      

  14.   

    1.final就是它修饰的变量的值不能改变,如果是引用类型那么它永远指向同一个对象。
    2.count每输出一种组合就+1,所以最后是总的组合数