import java.util.Scanner;
public class HexCalculator {
public static final int HEX = 16;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Input a decimal number:");
int value = in.nextInt();
System.out.println(calculate(value));
in.close();
}
public static char[] calculate(int value) {
char[] result;
int numOfBit = 1;
int hex = HEX;
while(hex <= value) {
numOfBit++;
hex *= HEX;
}
int index = 0;
int left = value;
result = new char[numOfBit];
while(numOfBit > 0) {
numOfBit--;
hex /= HEX;
result[index] = calHexBit(left / hex);
left = value % hex;
index++;
}
return result;
}
/**
* @param value from 0 to 15 decimal number.
* @return a char present hex number.
*/
public static char calHexBit(int value) {
switch(value) {
case 10:
return 'A';
case 11:
return 'B';
case 12:
return 'C';
case 13:
return 'D';
case 14:
return 'E';
case 15:
return 'F';
default:
return (char) ('0' + value);
}
}
}