In this Java tutorial, you’ll learn how to Convert Octal Number to Decimal and vice-versa using the Java programming language.
How to Convert Octal Number to Decimal and vice-versa using JAVA?
RUN CODE SNIPPETpublic class Main
{
public static void main(String[] args)
{
int decimal = 78;
int octal = convertDecimalToOctal(decimal);
System.out.printf("%d in decimal = %d in octal", decimal, octal);
}
public static int convertDecimalToOctal(int decimal)
{
int octalNumber = 0, i = 1;
while (decimal != 0)
{
octalNumber += (decimal % 8) * i;
decimal /= 8;
i *= 10;
}
return octalNumber;
}
}OUTPUT
78 in decimal = 116 in octal