by Dinesh Thakur

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 3: read num

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[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]);
          }
}

Convert decimal integer to octal number