(单选题)
写出下面程序的运行结果( )。
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。
