有几个数 比如:123
我要把他排列出 可能的组合
比如:132 213 231.....
要怎么 写程序啊 

解决方案 »

  1.   

    可以用循环写,但要知道是几个数。你这是三个数,则
    for (i=1,i<=3,i++){
      for (j=1,j<=3,j++){
         for (n=1,n<=3,n++){
            print i&j&n\t;
         }
      }
    }
      

  2.   

    差不多是这个意思吧:/*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package javatest;/**
     *
     * @author ZangXT
     */
    public class Main {    public static void main(String[] args) {
            int a[] = {1, 2, 3,4};
            perm(a, 0, a.length - 1);
        }    public static void perm(int[] buf, int start, int end) {
            if (start == end) {
                for (int i = 0; i <= end; i++) {
                    System.out.print(buf[i] + " ");
                }
                System.out.println();
            } else {
                for (int i = start; i <= end; i++) {
                    swap(buf, start, i);
                    perm(buf, start + 1, end);
                    swap(buf, start, i);
                }
            }
        }    private static void swap(int buf[], int i, int j) {
            int temp = buf[i];
            buf[i] = buf[j];
            buf[j] = temp;
        }
    }