每日一题7

  1. Math.round(11.5) 等于:()
    A 11
    B 11.5
    C 12
    D 12.5
    【解析】round是跟取整有关的函数
 public static void main(String[] args) {
        System.out.println("小数点后第一位=5");
        System.out.println("正数:Math.round(11.5)=" + Math.round(11.5));//12
        System.out.println("负数:Math.round(-11.5)=" + Math.round(-11.5));//-11
        System.out.println("小数点后第一位<5");
        System.out.println("正数:Math.round(11.46)=" + Math.round(11.46));//11
        System.out.println("负数:Math.round(-11.46)=" + Math.round(-11.46));//-11
        System.out.println("小数点后第一位>5");
        System.out.println("正数:Math.round(11.68)=" + Math.round(11.68));//12
        System.out.println("负数:Math.round(-11.68)=" + Math.round(-11.68));//-12
    }

规则:四舍五入,等于5时加上0.5后,向下取整。
Math类中提供了三个与取整有关的方法:ceil,floor,round,这些方法的作用于它们的英文名称的含义相对应,例如:ceil的英文意义是天花板,该方法就表示向上取整,Math.ceil(11.3)的结果为12,Math.ceil(-11.6)的结果为-11;
floor的英文是地板,该方法就表示向下取整,Math.floor(11.6)的结果是11
Math.floor(-11.4)的结果-12;
round方法,表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下取整,所以,Math.round(11.5)的结果是12,Math.round(-11.5)的结果为-11。
2. 以下 _____ 不是 Object 类的方法
A clone()
B finalize()
C toString()
D hasNext()
【解析】Object() 中的方法有:clone() equals() finalize() getClass() hashCode() notify() notifyAll() toString() wait()
在这里插入图片描述

  1. Java采用的字符集编码——Unicode(标准码) UTF-8 是目前互联网上使用最广泛的一种 Unicode 编码方式.
  2. 【最小公倍数】
    求两个数的最小公倍数,两个数的最小公倍数为:能被这两个数同时整除的最小的数。
    最小公倍数= 两数乘积除以最大公约数(两数相乘防止过大越界,一般是颠倒一下顺序,可以先a/最大公约数*b);最大公约数用了辗转相除法
 public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int ret = min(a,b);
        System.out.println(ret);
    }
    
    public static int max(int a,int b){
        while(b != 0){
            int tmp = a%b;
            a=b;
            b=tmp;
        }
        return a;
    }
    public static int min(int a, int b){
        return a/max(a,b)*b;//防止a*b出界
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值