题解 | #进制转换#

进制转换

http://www.nowcoder.com/practice/8f3df50d2b9043208c5eed283d1d4da6

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            String str = scanner.nextLine();
            System.out.println(baseChange(str));
        }
    }

    private static int baseChange(String s){
        int i = s.length()-1;
        int res = 0;
        int pow = 0;
        while(i >= 2){
            char c = s.charAt(i);
            if(c >= 65){
                res += (c-55) * Math.pow(16, pow);
            }else{
                res += (c-48) * Math.pow(16, pow);
            }
            i--;
            pow++;
        }
        return res;
    }
全部评论

相关推荐

一表renzha:不是你说是南通我都没往那方面想,人家真是想表达那个意思吗?
点赞 评论 收藏
分享
MinJerous:虽然我一直说 计算机不怎么卡学历 但是至少得一本
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务