# Java program to convert float decimal to Octal number

Java 8Object Oriented ProgrammingProgramming

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.

## 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);
}
}

## Output

Octal of given decimal is 124
Published on 01-Nov-2018 09:21:53