title: Converting int to hex string using recursion
body: <p>I'm doing an assignment where I have to convert an integer number to a hexadecimal string using recursion. I have to do this using a method that returns a string value. I tried to turn the method I'm using on paper into code and it works just fine:</p>
  
  <pre><code>public class ItH {
  private static String intToHex(int n) {
      int temp = n % 16;
      String digit = "";
  
      if (temp &lt; 10) digit += temp;
      if (temp &gt; 9) {
          switch (temp) {
              case 10: digit="A"; break;
              case 11: digit="B"; break;
              case 12: digit="C"; break;
              case 13: digit="D"; break;
              case 14: digit="E"; break;
              case 15: digit="F"; break;
          }
      }
      if (n &gt; 0) return intToHex((n-temp)/16) + digit;
      return "";
  }
  
  public static void main(String[] args) {
      System.out.println(intToHex(1234));
      System.out.println(intToHex(257));
      System.out.println(intToHex(0));
  }
  
  
  }
  </code></pre>
  
  <p>It works just fine for the first two examples used in the main method, but I can't get it to display zero. Is there a way to get it to display zero without modifying too much? I've been going over it for some time now and I can't figure out a way to do that without adding at least one zero before every other number.
  Any help would be appreciated.</p>