tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Java > Core > Integer > Decimal to Octal Conversion

Decimal to Octal Conversion 

The following example shows how to convert a number in Decimal system to Octal system and vice versa.

File Name  :  
com/bethecoder/tutorials/core/integer/Integer2Octal.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.core.integer;

public class Integer2Octal {

  /**
   @param args
   */
  public static void main(String[] args) {

    int num = 21;
    String str = Integer.toOctalString(num);
    System.out.println(num + "(decimal) in octal : " + str);
    
    num = Integer.parseInt(str, 8);
    System.out.println(str + "(octal) in decimal : " + num);
    
  }

}
   

It gives the following output,
21(decimal) in octal : 25
25(octal) in decimal : 21


                    Print

   



Books Recommendation

 
 
bl  br