使用Integer.parseInt(s,n)函数可以进行进制转换
其中s是输入的字符串,n是将字符串看作为n进制,函数会将字符串参数转换为十进制的整数。
如下是将16进制转换为10进制。
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()){
String s = sc.nextLine();
System.out.println(Integer.parseInt(s.substring(2),16));
}
}
}