-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateBinary.java
More file actions
33 lines (31 loc) · 961 Bytes
/
GenerateBinary.java
File metadata and controls
33 lines (31 loc) · 961 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
/**
* Created by MalhotR1 on 04/25/2017.
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
public class GenerateBinary {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
for (int t = 0; t < T; t++) {
int N = Integer.parseInt(br.readLine().trim());
for (int i = 1; i <= N ; i++) {
printBinary(i);
}
System.out.println();
}
}
private static void printBinary(int N) {
ArrayList<Integer> al = new ArrayList<>();
while (N > 0) {
al.add(N % 2);
N = N / 2;
}
for (int i = al.size() - 1; i >= 0 ; i--) {
System.out.print(al.get(i));
}
System.out.print(" ");
}
}