Java Program to convert decimal integer to octal number

Java 8Object Oriented ProgrammingProgramming

Use the toOctalString() method to convert decimal to octal. It returns a string representation of the integer argument as an unsigned integer in base 8. The following characters are used as octal digits: 01234567.

First, declare an int value, which you want to convert to octal.

int val = 99;

Now convert it to octal using the toOctalString() method.

Integer.toOctalString(val);

Example

 Live Demo

public class Demo {
   public static void main( String args[] ) {
      int val = 99;
      // converting to octal
      System.out.println(Integer.toOctalString(val));
   }
}

Output

143
raja
Published on 12-Nov-2018 16:42:11
Advertisements