80. JAVA Program to Convert Decimal number into Hexadecimal number.
How does this program work?
- This program is used to convert given Decimal number into equivalent of Hexadecimal number using java.
- That means convert number with base value 10 to base value 16.
- The integer entered by user will store in one variable. Divide that number by 16.
- Store the remainder when the number is divided by 2 in an array.
- If the remainder will less than 10 then we can add 48 to the remainder else we can add 55 to the remainder.
Here is the code
//To convert Decimal number into Hexadecimal number
import java.util.Scanner;public class Number
{
public static void main(String args[])
{
int num;
System.out.print("Enter a decimal number: \n");
Scanner skill = new Scanner( System.in );
num =skill.nextInt();
String str = Integer.toHexString(num);
System.out.println("The Equivalent hexadecimal number is "+str);
}
}