题解 | #进制A+B#

进制A+B

http://www.nowcoder.com/practice/6187581174ac48278ca3bccf8d534897

import java.util.Scanner;

// 使用字符串截取功能获取对应的16进制和8进制
// 去掉前置导向
// 使用Integer.parseInt的时候不可以有前置导向

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        // 16
        String s1 = s.substring(0, s.indexOf(" "));
        s1 = s1.substring(2);
        // 8进制
        String s2 = s.substring(s.indexOf(" ")+1);
        s2 = s2.substring(1);
        // 需要去掉前置导向
        int result = Integer.parseInt(s1, 16) + Integer.parseInt(s2, 8);
        System.out.print(result);
    }
}
全部评论

相关推荐

积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
_mos_:我以为手抄报简历就已经很顶了,没想到还有表格简历
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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