English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
We can convert any decimal number to its equivalent octal number using the following program.
Here, we keep the reminder obtained by dividing the given number by the base of octal, and divide it by8, and then multiply each reminder by10to reverse the order of reminders stored. The following example lets us understand.
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 Result
Octal of given decimal is 124