Java lang Long.toOctalString() Method with Examples

Java 8Object Oriented ProgrammingProgramming

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

Example

Let us now see an example −

import java.lang.*;
public class Main {
   public static void main(String[] args) {
      long l = 220;
      System.out.println("Number = " + l);
      /* returns the string representation of the unsigned long value
      represented by the argument in Octal (base 8) */
      System.out.println("Octal = " + Long.toOctalString(l));
   }
}

Output

Number = 220
Octal = 334

Example

Let us now see another example wherein negative number is considered −

import java.lang.*;
public class Main {
   public static void main(String[] args) {
      long l = -55;
      System.out.println("Number = " + l);
      System.out.println("Octal = " + Long.toOctalString(l));
   }
}

Output

Number = -55
Octal = 1777777777777777777711
raja
Updated on 24-Sep-2019 08:08:47

Advertisements