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進制
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.