进制转换

来源:互联网 发布:电磁波辐射测试仪软件 编辑:程序博客网 时间:2024/06/14 19:13

描述:写出一个程序,接受一个十六进制的数值字符串,输出该数值的十进制字符串。(多组同时输入 )
输入描述:输入一个十六进制的数值字符串。
输出描述:输出该数值的十进制字符串。
输入例子:0xA
输出例子:10

public class Main {     public static void main(String[] args) {        Scanner sc=new Scanner(System.in);        while(sc.hasNextLine()){            String str1=sc.nextLine();            //String str= str1.replaceAll("0x", "");            System.out.println(Integer.valueOf(str1.substring(2),16));            //System.out.println(Integer.valueOf(str,16));        }    }}
0 0