java语言的科学与艺术-编程练习7.1

import acm.program.*;
//输入16进制输出10进制
public class HexToDecimalConverter extends ConsoleProgram {
    public void run(){
        println("This program converts hexadecimal to decimal.");
        println("Enter 0 to stop.");
        while(true){
            String line = readLine("Enter a hexdecimal number: ");
            if(line.equals("0")) break;
            println(line + " hex" +  " = " + Integer.parseInt(line, 16) + " decimal");
        }
    }
}

 

posted on 2012-12-30 21:05  mybluecode  阅读(194)  评论(0编辑  收藏  举报