convert decimal to octal in java

The below program convert decimal to octal in java without using any inbuilt function

import java.io.*;

public class DecimalToOctal {

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 OctalNumber[] = new Integer[50];
int Counter = 0;

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

}
}
}

Output

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