Java Program to Convert Decimal to Octal

In this tutorial, we are going to see how to convert a decimal number to octal in Java using the Integer.toOctalString() method. The toOctalString() method is a built-in function in Java that is used to return a string representation of the integer argument as an unsigned integer in base 8.

Program to Convert Decimal to Octal in Java :
import java.util.Scanner;

class Main
    public static void main(String args[])
      Scanner sc = new Scanner(;
      System.out.print("Enter a decimal number : ");
      //read the decimal number
      int nbr = sc.nextInt();

      String str = Integer.toOctalString(nbr);
      System.out.println("The octal number is : "+str);


Enter a decimal number : 8
The octal number is : 10
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *