Math.round(11.5)等于()Math.round(-11.5)等于()
几天前去面试,这道简单的题目居然做错了,看来基础就是慢慢积累的。并不断使用和复习才会成为高手,假设基础不是那么熟练。恐怕在成为高手的路上会困难重重。所以在做项目的间歇时间。偶尔回顾一下最基础的知识。是一个比較好的投资。
好了。以下介绍的就是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
Math.round(11.5)等于()Math.round(-11.5)等于()的更多相关文章
- int和integer;Math.round(11.5)和Math.round(-11.5)
int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结
Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数,具体的区别请看下面的总结. 一.Math.round 作用:四舍五入,返回参数+0.5后,向下取整 ...
- BestCoder Round #29——A--GTY's math problem(快速幂(对数法))、B--GTY's birthday gift(矩阵快速幂)
GTY's math problem Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整小结
以前经常在代码中看到Math.round.parseInt.Math.floor和Math.ceil这四个函数,虽然知道结果都可以返回一个整数,但是对他们四者的区别还是不太清楚,今天就做一个小结. 一 ...
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整小结【转】
[摘要:之前常常正在代码中看到Math.round.parseInt.Math.floor战Math.ceil那四个函数,固然晓得效果皆能够返回一个整数,然则对他们四者的差别照样没有太清晰,本日便做一 ...
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结(转)
js中Math.round.parseInt.Math.floor和Math.ceil小数取整总结 Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数 ...
- 关于python中的round()和javascript中的round()的比较
ps:python的round()和javascript的round()的比较: javascript:Math.round():正常的标准舍入,就像我们学的数学课本上面的规则 python:pyth ...
- 图形化升级单机oracle 11.2.0.1 到 11.2.0.4
1. 讲补丁包上传到 oracle server ,解压.安装 [root@11g ~]#unzip p13390677_112040_Linux-x86-64_1of7.zip -d /tmp &a ...
- GTAC 2015将于11月10号和11号召开
今年的GTAC注册已经结束,将会在11月10号和11号在Google马萨诸塞州剑桥办公室召开.大家可以关注https://developers.google.com/google-test-autom ...
- C++11 并发指南一(C++11 多线程初探)
引言 C++11 自2011年发布以来已经快两年了,之前一直没怎么关注,直到最近几个月才看了一些 C++11 的新特性,今后几篇博客我都会写一些关于 C++11 的特性,算是记录一下自己学到的东西吧, ...
随机推荐
- SpringBoot优化内嵌的Tomcat
SpringBoot测试版本 <parent> <groupId>org.springframework.boot</groupId> <artifactId ...
- 14.3.5.1 Interaction of Table Locking and Transactions 表锁和事务的相互作用
14.3.5.1 Interaction of Table Locking and Transactions 表锁和事务的相互作用 LOCK TABLES 和UNLOCK TABLES 交互实用事务如 ...
- (五)boost库之随机数random
(五)boost库之随机数random boost库为我们提供了许多的日常随机数生成器: 1.uniform_smallint:在小整数域内的均匀分布 2.uniform_int:在整数域上的均匀分布 ...
- _declspec(dllexport)与_declspec(dllimport)
__declspec(dllexport)2009-03-04 17:25 我相信写WIN32程序的人,做过DLL,都会很清楚__declspec(dllexport)的作用,它就是为了省掉在DEF文 ...
- poj 1852 Ants_贪心
题目大意:很多的蚂蚁都在长度为L(cm)的膀子上爬行,它们的速度都是1cm/s,到了棒子终端的时候,蚂蚁就会掉下去.如果在爬行途中遇到其他蚂蚁,两只蚂蚁的方向都会逆转.已知蚂蚁在棒子的最初位置坐标,但 ...
- POJ 动态规划题目列表
]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...
- C Statements
1,while((ch = getchar()) != EOF){ putchar(ch);}2,while((ch=getchar()) != EOF){ if(ch < '0' ...
- hdu 5606 tree(并查集)
Problem Description There is a tree(the tree is a connected graph which contains n points and n−1 ed ...
- hdu 5562 Clarke and food(贪心)
Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned i ...
- Longtail Hedgehog(DP)
Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...