Java Program to convert integer to octal


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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements