Java program to convert decimal number to octal value

Java Programming Java Technologies

The java.lang.Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.

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

Example

import java.util.Scanner;
public class DecimalToOctal {
   public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter a decimal number ::");
      int decimal = sc.nextInt();
      String result = Integer.toOctalString(decimal);
      System.out.println("Octal value of the given decimal number is ::"+result);
   }
}

Output

Enter a decimal number ::
45
Octal value of the given decimal number is ::55
raja
Published on 25-Apr-2018 16:58:49
Advertisements