输入一个集合,输出这个集合的所有子集

package cn.edu.bupt.sherry;
import java.util.ArrayList;
import java.util.Scanner;
public class Test {
	/*
	 *  二级制 001 ——> index = 0 {list.get(0)}
	 */
	public static ArrayList> getSubsets2(ArrayList set){  
	    ArrayList> allsubsets = new ArrayList>();  
	    int max = 1 << set.size(); //how many sub sets  
	    for(int i=0; i s = new ArrayList();  
	        while(k > 0){  
	            if((k&1) > 0){  
	                s.add(set.get(index));  
	            }  
	            k>>=1;  
	            index++;  
	        }  
	        allsubsets.add(s);  
	    }  
	    return allsubsets;  
	} 
 
public static void main(String[] args){  
    ArrayList s = new ArrayList();  
    Scanner sc = new Scanner(System.in);
    System.out.println("请输入一串整数并在输入时用英文逗号隔开:");
    String inputString=sc.next().toString();
    String stringArray[]=inputString.split(",");
    int num[]=new int[stringArray.length];
    for(int i=0;i> allsubsets = getSubsets2(s);  
    for(ArrayList set : allsubsets){  
        System.out.println(set);  
    }
    }
}

你可能感兴趣的:(算法,java)