- Notifications
You must be signed in to change notification settings - Fork 445
Expand file tree
/
Copy pathpowerSet.java
More file actions
Latest commit
34 lines (29 loc) · 803 Bytes
/
Copy pathpowerSet.java
File metadata and controls
34 lines (29 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
importjava.util.*;
publicclasspowerSet{
publicstaticvoidmain(String[] args) {
String[] input = {"", "", ""};
if(args.length > 0){
for(inti = 0; i < args.length; i++){
input[i] = args[i];
}
}
LinkedHashSethashSet = newLinkedHashSet();
intlen = input.length;
intelements = (int) Math.pow(2, len);
for (inti = 0; i < elements; i++) {
Stringstring = Integer.toBinaryString(i);
intvalue = string.length();
Stringpset = string;
for (intk = value; k < len; k++) {
pset = "0" + pset;
}
LinkedHashSetset = newLinkedHashSet();
for (intj = 0; j < pset.length(); j++) {
if (pset.charAt(j) == '1')
set.add(input[j]);
}
hashSet.add(set);
}
System.out.println(hashSet);
}
}