Write a program to accept an integer No. from keyboard and convert it into other no system. This is a part of Mumbai University MCA Colleges Java Program
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
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.
No comments:
Post a Comment