# Convert Decimal Integer to Octal Number Example | Java Examples

by Dinesh Thakur Category: array

Algorithm for Convert decimal integer to octal Number:

step 1: set r=0, i=0

step 2: create two integer arrays a[],b[] of size 10

step 4: repeat through step-11 while num greater than 0

step 5: if num less than 8 then execute following codes otherwise goto

step- 9

step 6: a[i]=num

step 7: i=i+ 1

step 8: goto step-4

step 9: a[i]=num%8

step 10: i=i+ 1

step 11: num= num/ 8

step 12: initialize q=i-1

step 13: repeat through step-16 while q greater than or equals to 0

step 14: b[r]=a[q]

step 15: r=r+ 1

step 16: q=q-1

step 17: initialize q=0

step 18: repeat through step-20 while q less than r

step 19: print b[q]

step 20: q=q+ 1

step 21: Exit

Here is the Java Example for Convert Decimal integer to Octal 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;                       int b[]=new int;                       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