Convert Decimal to Octal in Java

Description

The following code shows how to convert Decimal to Octal.

Example


// w  ww .  j  a  v a 2s .c  o  m
public class Main {

  public static void main(String[] args) {
    int integer = 1024;

    String octal = Integer.toOctalString(integer);

    System.out.printf("Octal value of %d is '%s'.\n", integer, octal);
    System.out.printf("Octal value of %1$d is '%1$o'.\n", integer);

    int original = Integer.parseInt(octal, 8);
    System.out.printf("Integer value of octal '%s' is %d.", octal, original);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Java Data Type »




Java Boolean
Java Byte
Java Character
Java Currency
Java Double
Java Enum
Java Float
Java Integer
Java Long
Java Short
Java Auto Grow Array
Java Array Compare
Java Array Convert
Java Array Copy Clone
Java Array Fill
Java Array Search and Sort
Java String Convert
Java String File
Java String Format
Java String Operation
Java BigDecimal
Java BigInteger