Sunday 5 January 2020

How to print integer in octal format?

‘Integer.toOctalString’ method is used to convert an integer to octal string.

Example
int i = 1027;
String ocatlString = Integer.toOctalString(i);

App.java
package com.sample.app;

public class App {

 public static void main(String args[]) {
  int i = 1027;

  String ocatlString = Integer.toOctalString(i);
  
  System.out.println("Octal form of " + i + " is " + ocatlString);

 }
}

Output
Octal form of 1027 is 2003


You may like

No comments:

Post a Comment