Java.lang Package Classes

Java Integer - toOctalString() Method



The java.lang.Integer.toOctalString() method returns a string representation of the integer argument as an unsigned integer in base 8.

Syntax

public static String toOctalString(int i)

Parameters

i Specify a integer to be converted to a string.

Return Value

Returns the string representation of the unsigned integer value represented by the argument in octal (base 8).

Exception

NA.

Example:

In the example below, the java.lang.Integer.toOctalString() method returns a string representation of the integer argument as an unsigned integer in base 8.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating int value
    int x = 25;
    int y = 31;
    int z = 111;

    //creating and printing string representation of 
    //argument in octal system.
    System.out.println("x in octal system is: " + Integer.toOctalString(x)); 
    System.out.println("y in octal system is: " + Integer.toOctalString(y)); 
    System.out.println("z in octal system is: " + Integer.toOctalString(z));   
  }
}

The output of the above code will be:

x in octal system is: 31
y in octal system is: 37
z in octal system is: 157

❮ Java.lang - Integer

5