This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
importjava.util.Scanner;
publicclasscomputer{
// 将任意进制数转换为十进制数
publicstaticinttoDecimal(Stringnumber,intbase){
intdecimal=0;
intpower=0;
// 从字符串的末尾开始遍历
for(inti=number.length()-1;i>=0;i--){
chardigit=number.charAt(i);
intvalue;
// 处理0-9的数字字符
if(digit>='0'&&digit<='9'){
value=digit-'0';
}
// 处理A-F(或a-f)的十六进制字符
elseif(digit>='A'&&digit<='F'){
value=digit-'A'+10;
}elseif(digit>='a'&&digit<='f'){
value=digit-'a'+10;
}else{
thrownewIllegalArgumentException("Invalid character in number: "+digit);