Number Format Conversion Java

Ram Pothuraju
Write a program to accept an integer No. from keyboard and convert it into other no system. 

import java.io.*;
class Convert
{
 public static void main(String args[])throws IOException
  {
    BufferedReader br=new BufferedReader
    (new InputStreamReader(System.in));
    System.out.println("Enter an Integer");
    String str= br.readLine();
  
    int i=Integer.parseInt(str);
    System.out.println("In Decimal:"+i);
  
    str=Integer.toBinaryString(i);
    System.out.println("In Binary:"+str);

   str=Integer.toHexString(i);
   System.out.println("In HexaDecimal:"+str);

   str=Integer.toOctalString(i);
   System.out.println("In Octal:"+str);               
   }
}

The above program will take an input using InputStreamReader as an int and then convert the numbers to different number formats like Binary, Hexadecimal and Octal using the built in String conversion
Tags

Post a Comment

0Comments

Post a Comment (0)