Write a Java program to convert an octal number to its corresponding decimal form.


The standard way to convert octal to decimal is, to sum up, the product of each digit with its respective value of 8 to the power of its index (i.e position from the right – 1), as described in the image below.

Octal to Decimal

Let’s implement the same in Java.

Convert Octal to Decimal in Java using While Loop


Enter a Octal Number
Decimal: 12

Convert Octal to Decimal in Java using Recursion

The approach used in this method is the same as the above program but is implemented using recursion.

On each recursive call, we need to pass the octal number by eliminating its last digit. The recursive call will stop when there is only a single left in the octal (i.e base condition).


Enter a Octal Number
Decimal: 8

Comment below if there is some error in the code or post, also comment your doubts or suggestion if you have any.

Leave a Reply

15 + seventeen =