source file name: convdemo.java
import java.io.*;
class convdemo
{
public static void main(String as[])
{
int n=1;
System.out.println("enter value:");
try{
DataInputStream dis=new DataInputStream(System.in);
String s=dis.readLine();//accept input number from user
n=Integer.parseInt(s);
System.out.println("Binary conversion "+Integer.toBinaryString(n));
System.out.println("Octal conversion "+Integer.toOctalString(n));
String hexastr=Integer.toHexString(n);
System.out.println("Hexadecimal conversion "+hexastr.toUpperCase());
}
catch(Exception e)
{
System.out.println(e);
}
}
}
output 1:
D:\JavaPrograms\Misc>javac convdemo.java
D:\JavaPrograms\Misc>java convdemo
enter value:
100
Binary conversion 1100100
Octal conversion 144
Hexadecimal conversion 64
output 2:
D:\JavaPrograms\Misc>java convdemo
enter value:
1000
Binary conversion 1111101000
Octal conversion 1750
Hexadecimal conversion 3E8
0 Comments
Post a Comment