面试题8:Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
来源:互联网 发布:怎么经营淘宝店 编辑:程序博客网 时间:2024/04/28 16:32
问题:Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
/*
答:11.5+0.5后是12再向下取整是12;-11.5+0.5后是-11再向下取整-11
* 扩展: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。
*/
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);}}
0 0
- 面试题8:Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- 面试题: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)等于多少?
- C++面试宝典(整理版)1
- 面试题9:问题:是否可以从一个static方法内部发出对非static方法的调用?
- lua实现查找一个字符串中的某些字符
- 【Android】利用表格布局,Android中xml文件与java的交互制作登录界面
- Spark入门——4: Spark的存储管理模块
- 面试题8:Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- C 内存
- mark-web项目端的webservice开发
- LINK:fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏(VS2010)
- 要求选出1...n中第m个数字,直到全部选出
- 5.1-3
- 欧拉工程第50题:Consecutive prime sum
- HDU 5253 连接的管道
- Could not bind factory to JNDI