-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpattern.java
More file actions
36 lines (32 loc) · 720 Bytes
/
pattern.java
File metadata and controls
36 lines (32 loc) · 720 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
35
36
// Java program to convert a decimal
// number to binary number
import java.io.*;
class GFG
{
// function to convert decimal to binary
static void decToBinary(int n)
{
// array to store binary number
int[] binaryNum = new int[1000];
// counter for binary array
int i = 0;
while (n > 0)
{
// storing remainder in binary array
binaryNum[i] = n % 2;
n = n / 2;
i++;
}
// printing binary array in reverse order
for (int j = i - 1; j >= 0; j--)
System.out.print(binaryNum[j]);
}
// driver program
public static void main (String[] args)
{
int n = 17;
System.out.println("Decimal - " + n);
System.out.print("Binary - ");
decToBinary(n);
}
}