Home » Java Integer toOctalString() method with Examples

Java Integer toOctalString() method with Examples

by Online Tutorials Library

Java Integer toOctalString () Method

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

The following characters are used as octal digits:

Note: If the argument is negative, the unsigned integer value is the argument plus 232 otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in octal (base 8) with no extra leading 0s. If the unsigned magnitude is zero, it is represented by a single zero character ‘0’ otherwise, the first character representation of the unsigned magnitude will not be the zero character.

Explanation:

Decimal Number Operation (%) Quotient Remainder Octal Result
224 8 28 0 0
28 8 3 4 40
3 8 0 3 340

Hence:

Syntax:

Following is the declaration of toOctalString() method:

Parameter:

DataType Parameter Description Required/Optional
int i It specifies the number to be converted in octal string. Required

Returns:

The toOctalString() method returns the string representation of the unsigned integer value represented by the argument in octal (base 8).

Exceptions:

NA

Compatibility Version:

Java 1.0.2 and above.

Example 1

Test it Now

Output:

Number = 224 Octal representation is = 340 

Example 2

Output:

Enter the Number = 175 Number = 175 Octal representation is = 257 

Example 3

Test it Now

Output:

310 37777777470 1750 37777776030 

Next TopictoString() Method

You may also like