payal-kothari
8/10/2017 - 3:03 AM

recursive

recursive

import java.util.HashMap;

class S{

    public static HashMap<Integer, String> map = new HashMap<>();


    public String convertTo16(int num) {
        if (num < 16){
            return map.get(num) + "";
        }
        return convertTo16(num / 16) + map.get(num % 16);
    }

    public static void main(String[] args) {
        S s = new S();
        for(int i =0; i<10;i++){
            map.put(i, Integer.toString(i));
        }
        map.put(10,"A");
        map.put(11,"B");
        map.put(12,"C");
        map.put(13, "D");
        map.put(14,"E");
        map.put(15,"F");
        String ans = s.convertTo16(110);
        System.out.println(ans);
    }
}