题解 | #进制转换#
进制转换
http://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6
进制转化
就从输入第三个字符开始进行遍历,判断是数组还是字母,然后进行分别处理
import java.util.*; public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ String str = scanner.nextLine(); int len = str.length(); int ans = 0, temp = 0; for(int i = 2; i < len; i++){ char c = str.charAt(i); if(Character.isDigit(c)){ temp = c - '0'; }else{ temp = c - 'A' + 10; } ans = ans * 16 + temp; } System.out.println(ans); } } }