Convert Decimal to Binary, Octal and Hexadecimal Java

PROGRAM TO CONVERT DECIMAL TO BINARY, OCTAL AND HEXADECIMAL


  1. class Convert
  2. {
  3.     Scanner scan;
  4.     int num;
  5.     void getVal()
  6.      {
  7.           System.out.println("Decimal to HexaDecimal,Octal and Binary");
  8.           scan = new Scanner(System.in);
  9.           System.out.println("\nEnter the number :");
  10.           num = Integer.parseInt(scan.nextLine());
  11.      }
  12.     void convert()
  13.       {
  14.            String hexa = Integer.toHexString(num);
  15.            System.out.println("HexaDecimal Value is : " + hexa);
  16.            String octal = Integer.toOctalString(num);
  17.            System.out.println("Octal Value is : " + octal);
  18.            String binary = Integer.toBinaryString(num);
  19.            System.out.println("Binary Value is : " + binary);
  20.        }
  21. }
  22. class Decimal_Conversion
  23. {
  24.    public static void main(String args[])
  25.     {
  26.         Convert obj = new Convert();
  27.          obj.getVal();
  28.          obj.convert();
  29.     }
  30. }

OUTPUT
Decimal to HexaDecimal,Octal and Binary
 
Enter the number :
121
HexaDecimal Value is : 79
Octal Value is : 171
Binary Value is : 1111001

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java