Java Program to convert integer to octal

Java 8Object Oriented ProgrammingProgramming

To convert integer to octal in Java, use the Integer.toOctalString() method.

Let’s say the following is our integer.

int val = 768;

Convert the above integer to octal.

Integer.toOctalString(val)

The following is the final example.

Example

 Live Demo

public class Demo {
    public static void main(String[] args) {
       int val = 768;
       // integer
       System.out.println("Integer: "+val);
       // octal
       System.out.println("Octal String = " + Integer.toOctalString(val));
    }
}

Output

Integer: 768
Octal String = 1400
raja
Published on 12-Dec-2018 06:43:51
Advertisements