-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubsets.java
More file actions
40 lines (32 loc) · 1.03 KB
/
subsets.java
File metadata and controls
40 lines (32 loc) · 1.03 KB
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
35
36
37
38
39
40
/* *****************************************************************************
* Name: Ada Lovelace
* Coursera User ID: 123456
* Last modified: October 16, 1842
**************************************************************************** */
import java.util.Scanner;
public class subsets {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scn.nextInt();
}
int total = (int) Math.pow(2, n);
for (int i = 0; i < total; i++) {
int num = i;
String str = "";
for (int j = n - 1; j >= 0; j--) {
int rem = num % 2;
num = num / 2;
if (rem == 1) {
str = a[j] + "\t" + str;
}
else {
str = "-\t" + str;
}
}
System.out.println(str);
}
}
}