用java实现十进制转十六进制的答案源码
package nameyu;import java.util.Scanner;public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.print("Enter a decimal value(0 to 15) :"); int number=input.nextInt(); if(number>=0&&number<=9){ System.out.println("The hex value is "+number); } else if(number>=10&&number<=15){ char ch=(char)(number+'A'-10); System.out.println("The hex value is "+ch); } else System.out.println(number+" is an invalid input"); } }
页:
[1]