Java Integer toOctalString() method
The toOctalString() method of Java Integer class returns a string representing the specified int argument as an unsigned integer in base 8. Syntax public static String toOctalString (int i) Parameters The parameter ‘i’ represents an integer to be converted to a string. Return Value This method returns the string which represents the unsigned integer value of the argument in octal i.e. base 8. Example 1
public class JavaIntegerToOctalStringExample1 { public static void main(String[] args) { Integer val=2; String val1=Integer.toOctalString(val); //It returns a string representation of the integer argument as an unsigned integer in base 8 System.out.println("Octal String : "+val1); } }Output
Octal String : 2Example 2
public class JavaIntegerToOctalStringExample2 { public static void main(String[] args) { //passing negative value Integer val=-98623; String val1=Integer.toOctalString(val); //It returns a string representation of the integer argument as an unsigned integer in base 8 System.out.println("Octal String : "+val1); } }Output
Octal String : 37777477301Example 3
public class JavaIntegerToOctalStringExample3 { public static void main(String[] args) { //passing the minimum value Integer val=Integer.MIN_VALUE; String val1=Integer.toOctalString(val); //It returns a string representation of the integer argument as an unsigned integer in base 8 System.out.println("Octal String : "+val1); } }Output
Octal String : 20000000000Example 4
public class JavaIntegerToOctalStringExample4 { public static void main(String[] args) { //passing maximum value Integer val=Integer.MAX_VALUE; String val1=Integer.toOctalString(val); //It returns a string representation of the integer argument as an unsigned integer in base 8 System.out.println("Octal String : "+val1); } }Output
Octal String : 17777777777