题解 | #进制转换#

进制转换

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

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        
        String num=sc.nextLine().substring(2).toUpperCase();
        
        int res=0;
        int temp;
        while(num.length()>0){
            if(num.charAt(0)>='A'&&num.charAt(0)<='F'){
                temp=num.charAt(0)-'A'+10;
            }else{
                temp=num.charAt(0)-'0';
            }
            res=res*16+temp;
            num=num.substring(1);
        }
        System.out.println(res);
    }
}

全部评论

相关推荐

LemontreeN:有的兄弟有的我今天一天面了五场,4个二面一个hr面
投递字节跳动等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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