举例,例如存在集合{1,2,3,4,5},列举所有的子集合。
代码如下:
public static void main(String[] args) {
int[] a = { 1, 3, 4, 5 };
show_jihe(a);
}
public static void show_jihe(int[] a) {
if (null == a)
return;
int all_jihe = (1 << a.length) - 1;
int m = 0;
for (int i = 0; i <= all_jihe; i++) {
for (int j = 0; j < a.length; j++) {
if ((i & (1 << j)) > 0) {
System.out.print(a[j]);
}
}
System.out.print("***************" + (m++) + "\n");
}
}