title: Convert Decimal to Hex using Recursive method Java
body: <p>I need to make a recursive method that converts a decimal into hexadecimal.
  I can't use <code>Integer.toHexString</code>.
  EDIT:I tried this code but it doesn't work properly</p>
  
  <pre><code>public static String Hexa(String s) {
      String result = "";
      int n = Integer.parseInt(s);
      int remainder = n % 16;
  
      if (n == 0) {
          return Integer.toString(0);
      } else {
          switch (remainder) {
              case 10:
                  result = "A" + result;
                  break;
              case 11:
                  result = "B" + result;
                  break;
              case 12:
                  result = "C" + result;
                  break;
              case 13:
                  result = "D" + result;
                  break;
              case 14:
                  result = "E" + result;
                  break;
              case 15:
                  result = "F" + result;
                  break;
              default: result = Integer.toString(n/16) + result; break;
          }
          System.out.println(result);
          return Hexa(Integer.toString(n/16)) + result;
      }
  }
  </code></pre>
  
  <p>Edit: 
  Changed the <code>default</code> case and the <code>if (n == 0)</code> loop return statement and it works beautifully now.</p>
  
  <p>new code:</p>
  
  <pre><code> public static String Hexa(String s) {
          String result = "";
          int n = Integer.parseInt(s);
          int remainder = n % 16;
  
          if (n == 0) {
              return "";
          } else {
              switch (remainder) {
                  case 10:
                      result = "A";
                      break;
                  case 11:
                      result = "B";
                      break;
                  case 12:
                      result = "C";
                      break;
                  case 13:
                      result = "D";
                      break;
                  case 14:
                      result = "E";
                      break;
                  case 15:
                      result = "F";
                      break;
                  default:
                      result = remainder + result;
                      break;
              }
              return Hexa(Integer.toString(n / 16)) + result;
          }
      }
  </code></pre>