Math.round(11.5)等于()Math.round(-11.5)等于()
2016-02-23 10:39
183 查看
几天前去面试,这道简单的题目居然做错了,看来基础就是慢慢积累的。并不断使用和复习才会成为高手,假设基础不是那么熟练。恐怕在成为高手的路上会困难重重。所以在做项目的间歇时间。偶尔回顾一下最基础的知识。是一个比較好的投资。
好了。以下介绍的就是Math类中三个与取整有关的方法 :
1、Math.round();//四舍五入
2、Math.ceil();//向上取整
3、Math.floor();//向下取整
代码展示:
执行结果:
12
-11
12.0
-11.0
11.0
-12.0
好了。以下介绍的就是Math类中三个与取整有关的方法 :
1、Math.round();//四舍五入
2、Math.ceil();//向上取整
3、Math.floor();//向下取整
代码展示:
public class TextOne { public static void main(String[] args) { /** * 四舍五入取整 */ System.out.println(Math.round(11.5)); System.out.println(Math.round(-11.5)); /** *向上取整 */ System.out.println(Math.ceil(11.5)); System.out.println(Math.ceil(-11.5)); /** * 向下取整 */ System.out.println(Math.floor(11.5)); System.out.println(Math.floor(-11.5)); } }
执行结果:
12
-11
12.0
-11.0
11.0
-12.0
相关文章推荐
- Mootools遮罩层练习(原为网上的jquery写法)
- sharepoint报HRESULT:0x80131904的错误的原因和解决方法
- 本地图片选择(打开媒体库,选择图片)
- 前端架构
- FZU - 1894选拔志愿者【单调队列】
- 使用xtrabackup对MySQL进行备份和恢复
- c/c++内存机制(一)
- adb shell 访问真机手机数据库文件
- nagios setup
- Replacement(思维题)
- 打包程序时的证书问题(上传APP就出现Missing iOS Distribution signing indetity for)
- spring项目中监听器作用-ContextLoaderListener
- Workerman WebSocket示例
- 无废话ExtJs 入门教程十七[列表:GridPanel]
- UNREAL® ENGINE END USER LICENSE AGREEMENT
- Linux Mint 开发者被批评不专业
- 1024. Palindromic Number (25)
- 电商中台订单集成
- 关于基础和软硬件配合的简单思考
- 【Android】【Other】Android一些常用命令