convert decimal to binary in java

The below code convert decimal to binary in java without using any inbuilt function

import java.io.*;

public class DecimalToBinary {

public static void main(String[] args) {
try {
DataInputStream in = new DataInputStream(System.in);
System.out.print(“Enter the Decimal Number :- “);
int DecimalNumber = Integer.parseInt(in.readLine());

Integer BinaryNumber[] = new Integer[50];
int Counter = 0;

while (DecimalNumber > 0) {
BinaryNumber[Counter++] = DecimalNumber % 2;
DecimalNumber = DecimalNumber / 2;
}
Counter–;
System.out.print(“Binary Number is ==> “);
while (Counter >= 0) {
System.out.print(BinaryNumber[Counter–]);
}
} catch (Exception e) {

}
}
}

Output

Enter the Decimal Number :- 786
Binary Number is ==> 1100010010