We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 18cc865 commit 1029a36Copy full SHA for 1029a36
1 file changed
Bit Manipulation/PowerSet.java
@@ -0,0 +1,31 @@
1
+// Question
2
+// Generate Power set using Bitwise operator
3
+
4
+// Sample Case
5
+// Input="ab"
6
+// Output="","a","b","ab"
7
8
+package javaquestion;
9
10
+import java.util.*;
11
12
+public class power {
13
+ static void subset(String s) {
14
+ int a = s.length();
15
+ int pow = (int) Math.pow(2, a);
16
+ for (int counter = 0; counter < pow; counter++) {
17
+ for (int j = 0; j < a; j++) {
18
+ if ((counter & (1 << j)) != 0) {
19
+ System.out.print(s.charAt(j));
20
+ }
21
22
+ System.out.println();
23
24
25
26
+ public static void main(String[] args) {
27
+ Scanner sc = new Scanner(System.in);
28
+ String s = sc.next();
29
+ subset(s);
30
31
+}
0 commit comments