Java Program to Convert Decimal to Octal

« Previous Program Next Program »

Convert Decimal to Octal

To convert decimal to octal in Java Programming, you have to ask to the user to enter any number in decimal number format to convert it into octal number format to display the equivalent value in octal number system as shown in the following program.

Java Programming Code to Convert Decimal to Octal

Following Java Program ask to the user to enter any number in decimal to convert it into octal, then display the result on the screen :

/* Java Program Example - Convert Decimal to Octal */
import java.util.Scanner;

public class JavaProgram
    public static void main(String args[])
        int decnum, rem, quot, i=1, j;
        int octnum[] = new int[100];
        Scanner scan = new Scanner(;
        System.out.print("Enter any Decimal Number : ");
        decnum = scan.nextInt();
        quot = decnum;
        while(quot != 0)
            octnum[i++] = quot%8;
            quot = quot/8;
        System.out.print("Equivalent Octal Value of " + decnum + " is :\n");
        for(j=i-1; j>0; j--)

When the above Java Program is compile and executed, it will produce the following output:

Java Program convert decimal to octal

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:

Java Online Test

« Previous Program Next Program »

© Copyright 2021. All Rights Reserved.