Output

Variable Name     Value in Memory
decimal
hexValue
hexDigit
totalMinutes
currentMinute
totalHours
currentHour
empty string
0 1 2 3 4 5 6 7 8 9
a a a a a a a a a a
hex
  1  import java.util.Scanner;
  2  
  3  public class Dec2Hex {
  4    /** Main method */
  5    public static void main(String[] args) {
  6      // Create a Scanner
  7      Scanner input = new Scanner(System.in);
  8  
  9      // Prompt the user to enter a decimal integer
 10      System.out.print("Enter a decimal number: ");
 11      int decimal = input.nextInt();
 12  
 13      // Convert decimal to hex
 14      String hex = "";
 15      
 16      while (decimal != 0) {
 17        int hexValue = decimal % 16; 
 18        
 19        // Convert a decimal value to a hex digit 
 20        char hexDigit = (0 <= hexValue && hexValue <= 9) ?
 21          (char)(hexValue + '0') : (char)(hexValue - 10 + 'A');
 22        
 23        hex = hexDigit + hex;
 24        decimal = decimal / 16;
 25      }
 26      
 27      System.out.println("The hex number is " + hex);
 28    }
 29  }