题目描述
写出一个程序,接受一个十六进制的数值字符串,输出该数值的十进制字符串。(多组同时输入 )
输入描述:
输入一个十六进制的数值字符串。
输出描述:
输出该数值的十进制字符串。
输入例子:
0xA
输出例子:
10public class Main{ public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); while(in.hasNext()){ String s = in.nextLine(); int len = s.length(); int num = 0; for(int i = 2; i<len; i++){ char ch = s.charAt(i); int ele ; if(ch<='9'&&ch>='0'){ ele = ch-'0'; }else if(ch<='F'&&ch>='A'){ ele = ch-'A'+10; }else if(ch<='f'&&ch>='a'){ ele = ch -'a'+10; }else break; num = num*16+ele; } System.out.println(num); } } }