import java.util.*;
public class ten_sixteen {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.print("enter a number: ");
int decimal=input.nextInt();
System.out.println(decimal+ " is " +decimaltohex(decimal));
}
public static String decimaltohex(int decimal) {
String hex="";
while(decimal!=0) {
int hexvalue=decimal%16;
hex=tohexchar(hexvalue)+hex;
decimal/=16;
}
return hex;
}
public static char tohexchar(int hexvalue) {
if(hexvalue<=9&&hexvalue>=0)
return (char)(hexvalue+'0');
else
return (char)(hexvalue-10+'A');
}
}
java十进制转换16进制
最新推荐文章于 2024-08-25 04:01:32 发布