logo
首页 课程 题库 资讯 师资
加微福利
APP 400-8989-766
search
公考题库 > 通用 > 公基

(单选题)

写出下面程序的运行结果( )。
public static void main(String[] args){
System.out.print(Math.round(11.5)+“,”);
System.out.print(Math.round(-11.5)+“,”);
System.out.print(Math.ceil(11.3)+“,”);
System.out.print(Math.ceil(-11.3)+“,”);
System.out.print(Math.floor(11.6)+“,”);
System.out.print(Math.floor(-11.6)+“,”);
}

A.12,-11,12,11,11,-12

B.12,-11,12,-11,11,-12

C.12,-11,11,-11,12,-12

D.12,-11,11,-11,11,-12

参考答案:B

参考解析:

Math.round求本身的四舍五入。round()方法可以这样理解:将括号内的数+0.5之后,向下取值。round(11.5)就是11.5+0.5=12,向下取值是12,所以round(11.5)=12;round(-11.5)就是-11.5+0.5=-11,向下取值是-11,所以round(-11.5)=-11。Math.ceil求最小的整数,但不小于本身。该方法就表示向上取整。所以,Math.ceil(11.3)的结果为12,Math.ceil(-11.3)的结果是-11。Math.floor求最大的整数,但不大于本身。该方法就表示向下取整。所以,Math.floor(11.6)的结果为11,Math.floor(-11.6)的结果是-12。B项正确,当选。故本题正确答案选B。

知识点:计算机系统概述 计算机 计算机基本知识 通用 公基
华图在线app

添加您的

专属公考咨询师

扫码领专属好礼

返回顶部