title: Decimal to Hex Conversion (Java)
body: <p>I wrote the following code to convert decimal to hex:</p>
  
  <pre><code>System.out.println("The decimal number you enter will be converted to its hexadecimal equivalent.");
  
      System.out.println("Please enter a decimal number: ");
  
      Scanner keyboard = new Scanner(System.in);
  
      int dec = keyboard.nextInt();
  
      int input = dec;
  
      String hex = "";
  
      char dig[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
  
      while(dec &gt; 0)
      {
          input = dec%16;
  
          hex = dig[input] + hex;
  
          dec = dec / 16;
      }
  
      System.out.println("The decimal number you entered, " + input + " is " + hex + " in hexadecimal.\n");
  </code></pre>
  
  <p>The conversion works perfectly, but the output, specifically where the decimal input should be is not correct.  I understand that it is because I'm modifying the value in the while loop, and I am sure it is an easy fix, but I cannot for the life of me figure out how to keep the code, for the most part, the way it is and display the original decimal value entered.  A nudge (I'm not looking for the answer) in the right direction would be greatly appreciated.</p>