import java
.util
.Scanner
;
public class Month {
public static void main(String
[] args
){
Scanner input
=new Scanner(System
.in
);
System
.out
.println("输入一个16进制的数字");
String hex
=input
.nextLine();
System
.out
.println("转成10进制后的数值为:"+hexToDecimal(hex
.toUpperCase()));
}
public static int hexToDecimal(String hex1
){
int decimal
=0;
for (int i
=0;i
<hex1
.length();i
++){
char c
=hex1
.charAt(i
);
decimal
=decimal
*16+hexCharToDecimal(c
);
}
return decimal
;
}
public static int hexCharToDecimal(char c1
){
if (c1
>='A'&&c1
<='F')
return c1
-'A'+10;
else
return c1
-'0';
}
}
转载请注明原文地址: https://mac.8miu.com/read-75411.html