将所输入之正整数,以二、八、十六进制表示出来。
怎么办呢?第一次碰java就被要求做这个,求大神帮忙
import java.util.*; public class HexadecimalConversionTest { public static void main(String[] args) { while (true) { Scanner in = new Scanner(System.in); System.out.print("Input number:"); int inputNumber = Integer.valueOf(in.nextLine()); System.out.println("Binary:" + Integer.toBinaryString(inputNumber)); System.out.println("Octal:" + Integer.toOctalString(inputNumber)); System.out.println("Hex:" + Integer.toHexString(inputNumber)); } } }
Input number:1 Binary:1 Octal:1 Hex:1 Input number:8 Binary:1000 Octal:10 Hex:8 Input number:16 Binary:10000 Octal:20 Hex:10 Input number:100 Binary:1100100 Octal:144 Hex:64