Skip to Content

Convert decimal integer to octal number example

  1. /*
  2.         Convert decimal integer to octal number example.
  3.         This example shows how to convert int to octal number using
  4.         toOctalString method of Integer wrapper class.
  5. */
  6.  
  7. public class ConvertIntToOctalExample {
  8.  
  9.         public static void main(String[] args) {
  10.                
  11.                 int i = 27;
  12.                
  13.                 String strOctalNumber = Integer.toOctalString(i);
  14.                
  15.                 System.out.println("Convert decimal number to octal number example");
  16.                 System.out.println("Octal value of " + i + " is " + strOctalNumber);
  17.                                                                        
  18.         }
  19. }
  20.  
  21. /*
  22. Output would be
  23. Convert decimal number to octal number example
  24. octal value of 27 is 33
  25. */