Convert Decimal to Binary, Octal and Hexadecimal Java
PROGRAM TO CONVERT DECIMAL TO BINARY, OCTAL AND HEXADECIMAL
class Convert
{
Scanner scan;
int num;
void getVal()
{
System.out.println("Decimal to HexaDecimal,Octal and Binary");
scan = new Scanner(System.in);
System.out.println("\nEnter the number :");
num = Integer.parseInt(scan.nextLine());
}
void convert()
{
String hexa = Integer.toHexString(num);
System.out.println("HexaDecimal Value is : " + hexa);
String octal = Integer.toOctalString(num);
System.out.println("Octal Value is : " + octal);
String binary = Integer.toBinaryString(num);
System.out.println("Binary Value is : " + binary);
}
}
class Decimal_Conversion
{
public static void main(String args[])
{
Convert obj = new Convert();
obj.getVal();
obj.convert();
}
}
OUTPUT
Decimal to HexaDecimal,Octal and Binary Enter the number : 121 HexaDecimal Value is : 79 Octal Value is : 171 Binary Value is : 1111001
Comments
Post a Comment