# Convert Decimal Integer to Binary Number Example | Java Examples

by Dinesh Thakur Category: array

Algorithm for Convert Decimal integer to Binary Number:
step 1: set i=0
step 3: create two integer arrays a[],b[] of size 20
step 4: repeat through step- 7 while num greater than 0

step 5: a[i]=num%2
step 6: i=i+1
step 7: num=num/ 2
step 8: set k=i-1
step 9: initialize j=0
step 10: repeat through step-14 while j less than i
step 11: b[j]=a[k]
step 12: print b[i]
step 13: k=k-1
step 14: j=j+ 1
step 15: Exit
Here is the Java Example for Convert Decimal integer to Binary Number:

```import java.util.Scanner;

public class ConvertDectoOctal

{

public static void main(String args[])

{

int r=0,q,o=0,num;

int a[]=new int[10];

int b[]=new int[10];

Scanner sl=new Scanner(System.in);

System.out.print("Enter a number : ");

num=sl.nextInt();

System.out.println("\nEntered Number is :->"+num);

while(num>0)

{

if(num<8)

{

a[o]=num;

o++;

break;

}

else

{

a[o]=num%8;

o++;

num=num/8;

}

}

for(q=o-1;q>=0;q--)

{

b[r]=a[q] ;

r++;

}

System.out.print("Octal number is :->");

for(q=0;q<r;q++)

System.out.print(b[q]);

}

}

```

Dinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles