首页 > 编程语言 > 详细

java做题记录

时间:2020-03-11 14:28:43      阅读:86      评论:0      收藏:0      [点我收藏+]

进制转换

package ch2;
import java.util.Scanner;
public class CG0311_2 {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in); 
        long  res=0 ,base = 1;
        String str;
        str = sc.next();
        int len = str.length();
        for(int i = len-1;i>=0;i--) {
            if( str.charAt(i)==1 ) {
                res += base;
            }
            base*=2;
        } 
        System.out.println(res);
        sc.close();
    }
}

 

 

 

double

package ch2;
import java.util.Scanner;
public class CG031101 {
    public static void main( String [] args ) { 
        Scanner in = new Scanner(System.in);
        long a,b;
        a = in.nextInt();
        b = in.nextInt(); 
        System.out.printf("128-bit hexadecimal number:\n%016x%016x\n",a,b);
        a = a<<1;
        if( b<=-1 )    a=a+1; 
        b=b<<1;
        System.out.printf("After doubling:\n%016x%016x\n",a,b);
    }
}
 

 

java做题记录

原文:https://www.cnblogs.com/SunChuangYu/p/12462160.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!