从数组中取3个数全排列

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class comb {
    
      
    public static void main(String[] args) {
        
        //全排列  n from m
        //int c[]={3,94,100,8,5,7,12,6};
        int c[]={3,94,100,6};
        List<int []> total=new ArrayList<int []>();
        
        int s=3;
        
        for(int i=0;i<c.length;i++){
            
            int tmp[]=  new int[s];
            //第一个位置
            tmp[0]=c[i];
            
            for(int k=0;k<c.length;k++){
                //第二个位置
                if(tmp[0]==c[k]) {continue;}else{ tmp[1]=c[k]; }
                
                for(int j=0;j<c.length;j++){
                    
                    if(c[j]==tmp[0]||c[j]==tmp[1]){    continue;}else
                    {                
                        //第三个位置
                        tmp[2]=c[j];
                    }
                                        
                    int t[]=  new int[s];
                    t[0]=tmp[0];
                    t[1]=tmp[1];
                    t[2]=tmp[2];
                    //排序
                    Arrays.sort(t);
                    System.out.println(tmp[0]+" "+tmp[1]+" "+tmp[2]);
                    total.add(t);
                }
            }
            
            
          
        } 
        
        // 过滤重复
          Set ss=new HashSet(total);
          List<int []> xxx=new ArrayList<int []>(ss); 
        
    }

 

posted on 2017-04-27 12:40  rojas  阅读(652)  评论(0编辑  收藏  举报