Skip to content

Commit 1d2bc9e

Browse files
author
Emmanuel Adefuye
committed
the latest code in the repo doesn't match what's on screen
1 parent ca25982 commit 1d2bc9e

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

powerSet.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.util.*;
2+
3+
public class powerSet{
4+
5+
public static void main(String[] args) {
6+
String[] input = {"", "", ""};
7+
if(args.length > 0){
8+
for(int i = 0; i < args.length; i++){
9+
input[i] = args[i];
10+
}
11+
}
12+
13+
LinkedHashSet hashSet = new LinkedHashSet();
14+
int len = input.length;
15+
int elements = (int) Math.pow(2, len);
16+
17+
for (int i = 0; i < elements; i++) {
18+
String string = Integer.toBinaryString(i);
19+
int value = string.length();
20+
String pset = string;
21+
for (int k = value; k < len; k++) {
22+
pset = "0" + pset;
23+
}
24+
25+
LinkedHashSet set = new LinkedHashSet();
26+
for (int j = 0; j < pset.length(); j++) {
27+
if (pset.charAt(j) == '1')
28+
set.add(input[j]);
29+
}
30+
hashSet.add(set);
31+
}
32+
System.out.println(hashSet);
33+
}
34+
}

0 commit comments

Comments
 (0)