面试题:Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
来源:互联网 发布:想在淘宝直播怎么弄 编辑:程序博客网 时间:2024/04/28 05:37
问题:Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
* 答:11.5+0.5后是12再向下取整是12;-11.5+0.5后是-11再向下取整-11
package java基础题目;public class Test14 {public static void main(String[] args) {ceil();floor();round();}// 测试Math类的ceil方法(天花板,向上取整)public static void ceil() {int a = (int) Math.ceil(11.3);// 12int b = (int) Math.ceil(-11.3);// -11System.out.println("a=" + a + ",b=" + b);}// 测试Math类的floor方法(地板,向下取整)public static void floor() {int a = (int) Math.floor(11.6);// 11int b = (int) Math.floor(-11.6);// -12System.out.println("a=" + a + ",b=" + b);}// 测试Math类的round方法(四舍五入法)public static void round() {int a = (int) Math.round(11.5);// 12 11.3+0.5 11int b = (int) Math.round(-11.5);// -11System.out.println("a=" + a + ",b=" + b);}}
* 扩展:Math类中提供了三个与取整有关的方法:ceil、floor、round,这些方法的作用
* 与它们的英文名称的含义相对应,例如,ceil的英文意义是天花板,该方法就表示向上取整,
* 所以,Math.ceil(11.3)的结果为12,Math.ceil(-11.3)的结果是-11;floor的英
* 文意义是地板,该方法就表示向下取整,所以,Math.floor(11.6)的结果为11,Math.floor(-11.6)
* 的结果是-12;最难掌握的是round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的
* 数字加上0.5后再向下取整,所以,Math.round(11.5)的结果为12,Math.round(-11.5)的结果为-11。
0 0
- 面试题:Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- 面试题8:Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- Math.round(11.5)等於多少? Math.round()
- Math.round(11.5)等於多少?
- Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- 记录-Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- 【JAVA基础小问题】Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- Math.round(11.5)等于多少?Math.round(-11.5)等于多少?
- Math.round(11.5)等于多少?Math.round(-11.5)等于多少?
- Math.round(11.5)等于多少?Math.round(-11.5)等于多少?
- Android基础系列-----------Android系统启动过程简析
- JavaScript DOM 编程艺术 第二版 学习笔记。
- C++ 智能指针详解
- (转载)ADS启动问题:The unexpected failure of a COM operation suggests that MWComHelpers may be missing
- Objective-C初接触 课堂笔记
- 面试题:Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- 【C语言】猜拳游戏,人与电脑对决
- execve源码分析
- 第十三周项目3——立体类族共有的抽象类
- 事件机制
- NSOperationQueue 方式开启线程
- 会员卡管理系统技术解析(十六)会员卡有效期更改
- TCP学习(一)版本
- 使用Pycluster包进行聚类分析实例