import java.util.HashMap;
import java.util.Scanner;
import java.util.StringJoiner;
public class convert
{
static char hexaChar[] = {'F','E','D','C','B','A'};
static String findHex(int no)
{
String result ="";
int rem;
while(no>0)
{
rem = no % 16;
if(rem > 9)
{
result = hexaChar[15 - rem] + result;
}
else
{
result = rem+result;
}
no = no/16;
}
return result;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in); System.out.println("Enter a number "); int num = sc.nextInt(); System.out.println("Hexa Decimal : "+findHex(num));
}
}
No comments:
Post a Comment