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

好了。以下介绍的就是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. Android NDK 下载

    Android NDK Android NDK, Revision 10 (July 2014) Platform(32-bit target) Package Size (Bytes) MD5 Ch ...

  2. [Leetcode][Python]45: Jump Game II

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 45: Jump Game IIhttps://oj.leetcode.com ...

  3. Opencv2.4.4作图像旋转和缩放

    关于下面两个主要函数的讲解: cv::getRotationMatrix2D(center, angle, scale); cv::warpAffine(image, rotateImg, rotat ...

  4. php信用卡卡号验证函数

    介绍一个php信用卡卡号验证函数,可以验证一个卡号是否是信用卡. function validateCard ($cardnumber){ $cardnumber = preg_replace (&q ...

  5. Android通过HTTP POST带參訪问asp.net网页

    在看了网络上非常多视频关于android通过HTTP POST或者GET方式訪问网页并获取数据的方法. 自己也copy了一份来測试.并通过C#.NET搭建了一个简单的后台,但发现传參时,依照网上的方式 ...

  6. 移动端H5页面之iphone6的适配

    iphone6 及 iphone 6 plus 已经出来一段时间了.很多移动端网站,以前写死body 为320px的,现在估计也忙着做适配了. 大屏幕手机其实一直有,只是以前大家没怎么重视,移动端的H ...

  7. DB2数据库常用基本操作命令

    点击开始菜单-->所有程序-->IBM-->DB2-->DB2COPY1-->命令行工具-->命令窗口一.DB2实例操作1.查看DB2数据库的版本及安装目录 E:\ ...

  8. 2016年gift上线相关知识点记录

    1.图片初始化加载 2.如何判断横屏 function horAver() { if (window.orientation == 90 || window.orientation == -90) { ...

  9. ImageButton与Button

    1.Button控件 Butotn控件,主要用来实现一些命令操作,通过注册监听事件来实现.首先需要在xml文档中放入一个button按钮. <Button android:id="@+ ...

  10. iOS 键盘弹出遮挡输入框

    #pragma mark 键盘弹出遮挡输入框 //开始编辑输入框的时候,软键盘出现,执行此事件 -(void)textFieldDidBeginEditing:(UITextField *)textF ...