java程序中的冗余组合



我想通过使用给定的字母打印所有可能的组合,而不更改字母顺序,所以我写了这个代码,但它会一次又一次地打印每一行有什么问题

public class Solutions {

    public static void main(String[] args) {
        //  Scanner scanner = new Scanner(System.in);
        c = "l u k".split(" ");
        Solutions solutions = new Solutions();
        solutions.combi(0);
        System.out.println("Number of combi = " + count);
        System.out.print(max);
    }
    static String[] c;
    static int count = 0;
    static int max = 0;

    public void combi(int start) {
        int j;
        if (start != 0) {
            String str = "";
            for (int i = 0; i < start; i++) {
               // System.out.print(c[i]);
                str += c[i];
            }

          //  System.out.println();
            count++;
        }
        for (j = start; j < c.length; j++) {

            combi(start + 1);

        }
    }
}
public void combi(int start) {
    int j;
    if (start != 0) {
        for (int i = 0; i < start; i++) {
            System.out.print(c[i]);
        }
        System.out.println();
        count++;
    } else {
        for (j = start+1; j <= c.length; j++) {
            combi(j);
        }
    }
}

最新更新