/* * File: HexToDecimalConverter.java * -------------------------------- * This program reads numbers from the user and converts them * from hexadecimal to decimal. * * Author: CS1MD3, Nov. 2008 */ import acm.program.*; public class HexToDecimalConverter extends ConsoleProgram { public void run() { println("This program converts hexadecimal to decimal."); println("Enter " + Integer.toString(SENTINEL) + " to stop."); while (true) { String hex = readLine("Enter a hexadecimal number: "); int n = Integer.parseInt(hex, 16); if (n == SENTINEL) break; println(hex + " hex = " + n + " decimal"); } } /* Sentinel constant */ private static final int SENTINEL = 0; }