几天前去面试,这道简单的题目居然做错了,看来基础就是慢慢积累的。并不断使用和复习才会成为高手,假设基础不是那么熟练。恐怕在成为高手的路上会困难重重。所以在做项目的间歇时间。偶尔回顾一下最基础的知识。是一个比較好的投资。

好了。以下介绍的就是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)等于()的更多相关文章

  1. int和integer;Math.round(11.5)和Math.round(-11.5)

    int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...

  2. js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结

    Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数,具体的区别请看下面的总结. 一.Math.round 作用:四舍五入,返回参数+0.5后,向下取整 ...

  3. 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 ...

  4. js中Math.round、parseInt、Math.floor和Math.ceil小数取整小结

    以前经常在代码中看到Math.round.parseInt.Math.floor和Math.ceil这四个函数,虽然知道结果都可以返回一个整数,但是对他们四者的区别还是不太清楚,今天就做一个小结. 一 ...

  5. js中Math.round、parseInt、Math.floor和Math.ceil小数取整小结【转】

    [摘要:之前常常正在代码中看到Math.round.parseInt.Math.floor战Math.ceil那四个函数,固然晓得效果皆能够返回一个整数,然则对他们四者的差别照样没有太清晰,本日便做一 ...

  6. js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结(转)

    js中Math.round.parseInt.Math.floor和Math.ceil小数取整总结 Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数 ...

  7. 关于python中的round()和javascript中的round()的比较

    ps:python的round()和javascript的round()的比较: javascript:Math.round():正常的标准舍入,就像我们学的数学课本上面的规则 python:pyth ...

  8. 图形化升级单机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 ...

  9. GTAC 2015将于11月10号和11号召开

    今年的GTAC注册已经结束,将会在11月10号和11号在Google马萨诸塞州剑桥办公室召开.大家可以关注https://developers.google.com/google-test-autom ...

  10. C++11 并发指南一(C++11 多线程初探)

    引言 C++11 自2011年发布以来已经快两年了,之前一直没怎么关注,直到最近几个月才看了一些 C++11 的新特性,今后几篇博客我都会写一些关于 C++11 的特性,算是记录一下自己学到的东西吧, ...

随机推荐

  1. Inno Setup使用上的几个问题 (转)

    Inno Setup使用上的几个问题: [问题一:Inno Setup 执行REG文件代码?][Run]Filename: "{win}\regedit.exe";Paramete ...

  2. LoggingApplicationListener

    org.springframework.boot:spring-boot:1.3.0.M1 spring-boot-1.3.0.M1.jar package org.springframework.b ...

  3. cf467A George and Accommodation

    A. George and Accommodation time limit per test 1 second memory limit per test 256 megabytes input s ...

  4. linux之SQL语句简明教程---HAVING

    那我们如何对函数产生的值来设定条件呢?举例来说,我们可能只需要知道哪些店的营业额有超过 $1,500.在这个情况下,我们不能使用 WHERE 的指令.那要怎么办呢?很幸运地,SQL 有提供一个 HAV ...

  5. FTP的主动模式和被动模式

    摘自http://blog.csdn.net/love_gaohz/article/details/50723164 http://my.oschina.net/binny/blog/17469 FT ...

  6. 关于CoreData的理解和使用.

    CoreData是苹果官方推出的一种方便的面向对象的存储方式,相信大家都已经对其有所了解,但是对于CoreData的概念大家都存在部分的误区.给大家推荐个网址是苹果的官方文档的翻译版(http://o ...

  7. Win8开发疑问与解答

    疑问:怎样获取开发者许可证 打开VS2012时,怎么在没有取得开发者许可证之前,屏蔽/跳过弹出的窗体“获取Windows8开发者许可证 你需要具有开发者许可证才能开发适用于......” 打开Blen ...

  8. hadoop结构出现后format变态

    14/07/10 18:50:47 FATAL conf.Configuration: error parsing conf file: com.sun.org                     ...

  9. android欢迎页源码

    直接上源码: import android.app.Activity; import android.content.Intent; import android.os.Bundle; import ...

  10. windows server 2003进行相邻磁盘扩容(server 2008的直接右键就可以解决)

    vCenter下的win server 2003 的D盘需要扩容,解决办法是,先将D盘由原来的200GB增加到了2TB(win server 2003选择MBR的限制),重启win server 20 ...