zoukankan      html  css  js  c++  java
  • 从数组中取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); 
            
        }
  • 相关阅读:
    隔离级别
    cookie
    session
    正则表达式
    hello2源代码解析
    servlet_filter简介
    web.xml
    Annotations
    Java design patterna
    CDI Features
  • 原文地址:https://www.cnblogs.com/rojas/p/6773630.html
Copyright © 2011-2022 走看看