Convert decimal number to Octal number.


 

Write a program to convert decimal to octal number.

Write java code Convert decimal number to Octal number.

Convert decimal to Octal Number using java.

import java.io.*;

public class binart2octal {

            public static void main(String[]args)throws IOException

            {

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

                        int a[]=new int[10];

                        int b[]=new int[10];

                        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

                        System.out.println("enter the decimal number to convert into octal");

                        num = Integer.parseInt(br.readLine());

                        while(num>0)

                        {                                  

                                                a[oc]=num%8;

                                                oc++;

                                                num=num/8;                          

                        }

                        for(q=oc-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]);

                                }

                }

 

}

 

No comments:

Post a Comment