1public class DecimalToHexExample2{
2public static String toHex(int decimal){
3 int rem;
4 String hex="";
5 char hexchars[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
6 while(decimal>0)
7 {
8 rem=decimal%16;
9 hex=hexchars[rem]+hex;
10 decimal=decimal/16;
11 }
12 return hex;
13}
14public static void main(String args[]){
15 System.out.println("Hexadecimal of 10 is: "+toHex(10));
16 System.out.println("Hexadecimal of 15 is: "+toHex(15));
17 System.out.println("Hexadecimal of 289 is: "+toHex(289));
18}}