Home » Java programming language

Java Integer class toOctalString() method with example

Integer class toOctalString() method: Here, we are going to learn about the toOctalString() method of Integer class with its syntax and example.
Submitted by Preeti Jain, on September 28, 2019

Integer class toOctalString() method

  • toOctalString() method is available in java.lang package.
  • toOctalString() method is used to represent an octal string of the given parameter [value] of integer type as an unsigned integer in base 8.
  • toOctalString() method is a static method, it is accessible with class name too and if we try to access the method with the class object then also we will not get an error.
  • toOctalString() method does not throw an exception at the time of conversion from integer to an octal string.

Syntax:

    public static String toOctalString (int value);

Parameter(s):

  • int value – represents the integer value to be converted.

Return value:

The return type of this method is int, it returns the octal string of the given parameter that represent the unsigned integer value.

Example:

// Java program to demonstrate the example 
// of toOctalString (int value) method of Integer class

public class ToOctalStringOfIntegerClass {
    public static void main(String[] args) {
        // Variables initialization
        int i1 = 10;
        int i2 = 20;
        int i3 = 30;
        int i4 = Integer.MAX_VALUE;
        int i5 = Integer.MIN_VALUE;

        // Integer instance creation
        Integer value = new Integer(i1);

        // It represents Octal string of the given
        // integer type i2 argument
        String s = value.toOctalString(i2);

        // Display Octal String Representation
        System.out.println("value.toOctalString(i2): " + s);

        // It represents Octal string of the given
        // integer type i3 argument
        s = value.toOctalString(i3);

        // Display Octal String Representation
        System.out.println("value.toOctalString(i3): " + s);

        // It represents Octal string of the given
        // integer type i4 argument
        s = value.toOctalString(i4);

        // Display Octal String Representation
        System.out.println("value.toOctalString(i4): " + s);

        // It represents Octal string of the given
        // integer type i5 argument
        s = value.toOctalString(i5);

        // Display Octal String Representation
        System.out.println("value.toOctalString(i5): " + s);
    }
}

Output

value.toOctalString(i2): 24
value.toOctalString(i3): 36
value.toOctalString(i4): 17777777777
value.toOctalString(i5): 20000000000






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.