Java program to convert float decimal to Octal number

We can convert any decimal number to its equivalent octal by following program.

In this we reserve the reminder we get after divide the given number by 8 as it is the base of Octal and then reverse the order of reminders we have stored by multiplying each reminder by 10.Let understand by following example.


 Live Demo

public class DecimalToOctal {
   public static void main(String[] args) {
      int decimal = 84;
      int octalNumber = 0, i = 1;
      while (decimal != 0) {
         octalNumber += (decimal % 8) * i;
         decimal /= 8;
         i *= 10;
      System.out.println("Octal of given decimal is " + octalNumber);


Octal of given decimal is 124

Updated on: 25-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started