1. public class MathDemo {
  2. public static void main(String args[]){
  3. /**
  4. * abs求绝对值
  5. */
  6. System.out.println(Math.abs(-10.4));    //10.4
  7. System.out.println(Math.abs(10.1));     //10.1
  8. /**
  9. * ceil天花板的意思,就是返回大的值,注意一些特殊值
  10. */
  11. System.out.println(Math.ceil(-10.1));   //-10.0
  12. System.out.println(Math.ceil(10.7));    //11.0
  13. System.out.println(Math.ceil(-0.7));    //-0.0
  14. System.out.println(Math.ceil(0.0));     //0.0
  15. System.out.println(Math.ceil(-0.0));    //-0.0
  16. /**
  17. * floor地板的意思,就是返回小的值
  18. */
  19. System.out.println(Math.floor(-10.1));  //-11.0
  20. System.out.println(Math.floor(10.7));   //10.0
  21. System.out.println(Math.floor(-0.7));   //-1.0
  22. System.out.println(Math.floor(0.0));    //0.0
  23. System.out.println(Math.floor(-0.0));   //-0.0
  24. /**
  25. * max 两个中返回大的值,min和它相反,就不举例了
  26. */
  27. System.out.println(Math.max(-10.1, -10));   //-10.0
  28. System.out.println(Math.max(10.7, 10));     //10.7
  29. System.out.println(Math.max(0.0, -0.0));    //0.0
  30. /**
  31. * random 取得一个大于或者等于0.0小于不等于1.0的随机数
  32. */
  33. System.out.println(Math.random());  //0.08417657924317234
  34. System.out.println(Math.random());  //0.43527904004403717
  35. /**
  36. * rint 四舍五入,返回double值
  37. * 注意.5的时候会取偶数
  38. */
  39. System.out.println(Math.rint(10.1));    //10.0
  40. System.out.println(Math.rint(10.7));    //11.0
  41. System.out.println(Math.rint(11.5));    //12.0
  42. System.out.println(Math.rint(10.5));    //10.0
  43. System.out.println(Math.rint(10.51));   //11.0
  44. System.out.println(Math.rint(-10.5));   //-10.0
  45. System.out.println(Math.rint(-11.5));   //-12.0
  46. System.out.println(Math.rint(-10.51));  //-11.0
  47. System.out.println(Math.rint(-10.6));   //-11.0
  48. System.out.println(Math.rint(-10.2));   //-10.0
  49. /**
  50. * round 四舍五入,float时返回int值,double时返回long值
  51. */
  52. System.out.println(Math.round(10.1));   //10
  53. System.out.println(Math.round(10.7));   //11
  54. System.out.println(Math.round(10.5));   //11
  55. System.out.println(Math.round(10.51));  //11
  56. System.out.println(Math.round(-10.5));  //-10
  57. System.out.println(Math.round(-10.51)); //-11
  58. System.out.println(Math.round(-10.6));  //-11
  59. System.out.println(Math.round(-10.2));  //-10
  60. }
  61. }
  1. public class MathDemo {
  2. public static void main(String args[]){
  3. /**
  4. * abs求绝对值
  5. */
  6. System.out.println(Math.abs(-10.4));    //10.4
  7. System.out.println(Math.abs(10.1));     //10.1
  8. /**
  9. * ceil天花板的意思,就是返回大的值,注意一些特殊值
  10. */
  11. System.out.println(Math.ceil(-10.1));   //-10.0
  12. System.out.println(Math.ceil(10.7));    //11.0
  13. System.out.println(Math.ceil(-0.7));    //-0.0
  14. System.out.println(Math.ceil(0.0));     //0.0
  15. System.out.println(Math.ceil(-0.0));    //-0.0
  16. /**
  17. * floor地板的意思,就是返回小的值
  18. */
  19. System.out.println(Math.floor(-10.1));  //-11.0
  20. System.out.println(Math.floor(10.7));   //10.0
  21. System.out.println(Math.floor(-0.7));   //-1.0
  22. System.out.println(Math.floor(0.0));    //0.0
  23. System.out.println(Math.floor(-0.0));   //-0.0
  24. /**
  25. * max 两个中返回大的值,min和它相反,就不举例了
  26. */
  27. System.out.println(Math.max(-10.1, -10));   //-10.0
  28. System.out.println(Math.max(10.7, 10));     //10.7
  29. System.out.println(Math.max(0.0, -0.0));    //0.0
  30. /**
  31. * random 取得一个大于或者等于0.0小于不等于1.0的随机数
  32. */
  33. System.out.println(Math.random());  //0.08417657924317234
  34. System.out.println(Math.random());  //0.43527904004403717
  35. /**
  36. * rint 四舍五入,返回double值
  37. * 注意.5的时候会取偶数
  38. */
  39. System.out.println(Math.rint(10.1));    //10.0
  40. System.out.println(Math.rint(10.7));    //11.0
  41. System.out.println(Math.rint(11.5));    //12.0
  42. System.out.println(Math.rint(10.5));    //10.0
  43. System.out.println(Math.rint(10.51));   //11.0
  44. System.out.println(Math.rint(-10.5));   //-10.0
  45. System.out.println(Math.rint(-11.5));   //-12.0
  46. System.out.println(Math.rint(-10.51));  //-11.0
  47. System.out.println(Math.rint(-10.6));   //-11.0
  48. System.out.println(Math.rint(-10.2));   //-10.0
  49. /**
  50. * round 四舍五入,float时返回int值,double时返回long值
  51. */
  52. System.out.println(Math.round(10.1));   //10
  53. System.out.println(Math.round(10.7));   //11
  54. System.out.println(Math.round(10.5));   //11
  55. System.out.println(Math.round(10.51));  //11
  56. System.out.println(Math.round(-10.5));  //-10
  57. System.out.println(Math.round(-10.51)); //-11
  58. System.out.println(Math.round(-10.6));  //-11
  59. System.out.println(Math.round(-10.2));  //-10
  60. }
  61. }

java中常用到的math方法(Math.PI、Math.random()、Math.abs(double)、Math.floor(double)、Math.ceil(double)、Math.round(double))的更多相关文章

  1. java中常用的字符串的截取方法

    java中常用的字符串的截取方法   1.length() 字符串的长度 例:char chars[]={'a','b'.'c'}; String s=new String(chars); int l ...

  2. java中常用的包、类、以及包中常用的类、方法、属性----sql和text\swing

    java中常用的包.类.以及包中常用的类.方法.属性 常用的包 java.io.*; java.util.*; java.lang.*; java.sql.*; java.text.*; java.a ...

  3. 【Java】Java中常用的String方法

    本文转载于:java中常用的String方法 1 length()字符串的长度 String a = "Hello Word!"; System.out.println(a.len ...

  4. Java高级特性 第2节 java中常用的实用类(1)

    一.Java API Java API即Java应用程序编程接口,他是运行库的集合,预先定义了一些接口和类,程序员可以直接调用:此外也特指API的说明文档,也称帮助文档. Java中常用的包: jav ...

  5. Java 中的浮点数取精度方法

    Java 中的浮点数取精度方法 一.内容 一般在Java代码中取一个double类型的浮点数的精度,四舍五入或者直接舍去等的方式,使用了4种方法,推荐使用第一种,我已经封装成工具类了. 二.代码实现 ...

  6. java 中常用的类

    java 中常用的类 Math Math 类,包含用于执行基本数学运算的方法 常用API 取整 l  static double abs(double  a) 获取double 的绝对值 l  sta ...

  7. java中常用的工具类(二)

    下面继续分享java中常用的一些工具类,希望给大家带来帮助! 1.FtpUtil           Java   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  8. Java中常用的查找算法——顺序查找和二分查找

    Java中常用的查找算法——顺序查找和二分查找 神话丿小王子的博客 一.顺序查找: a) 原理:顺序查找就是按顺序从头到尾依次往下查找,找到数据,则提前结束查找,找不到便一直查找下去,直到数据最后一位 ...

  9. java中常用的工具类(三)

    继续分享java中常用的一些工具类.前两篇的文章中有人评论使用Apache 的lang包和IO包,或者Google的Guava库.后续的我会加上的!谢谢支持IT江湖 一.连接数据库的综合类       ...

  10. java中常用的工具类(一)

    我们java程序员在开发项目的是常常会用到一些工具类.今天我汇总了一下java中常用的工具方法.大家可以在项目中使用.可以收藏!加入IT江湖官方群:383126909 我们一起成长 一.String工 ...

随机推荐

  1. 赵雅智_SimpleCursorAdapter

    项目步骤 声明listView控件并获取显示的视图 获取显示的数据 设置显示的adapter 注冊点击事件 详细案例 实现效果: watermark/2/text/aHR0cDovL2Jsb2cuY3 ...

  2. a column-oriented DBMS

    https://clickhouse.yandex/docs/en/introduction/what_is_clickhouse.html

  3. 【腾讯bugly干货分享】精神哥手把手教你怎样智斗ANR

    上帝说要有ANR,于是Bugly就有了ANR上报.那么ANR究竟是什么? 近期非常多童鞋问起精神哥ANR的问题,那么这次就来聊一下,鸡爪怎么泡才好吃.噢不,是怎样高速定位ANR. ANR是什么 简单说 ...

  4. javascript查找子节点时,html里的换行可能会被当成节点

    1.直接去HTML里找到该换行的地方去掉换行 2.写一个方法把元素类型为空格而且是文本都删除 function del_ff(elem){ var elem_child = elem.childNod ...

  5. kafka2

    Master-Slave: 读写分离,save复制master的数据.同步复制:保证了强一致性但是会影响高可用性,因为写入的时候要保证slave都写入了才能返回告诉生产者数据写入成功,如果slave过 ...

  6. YTU 2442: C++习题 矩阵求和--重载运算符

    2442: C++习题 矩阵求和--重载运算符 时间限制: 1 Sec  内存限制: 128 MB 提交: 1457  解决: 565 题目描述 有两个矩阵a和b,均为2行3列.求两个矩阵之和.重载运 ...

  7. 使用Navicat连接MySQL出现1251错误

    问题:navicat连接mysql时报错:1251-Client does not support authentication protocol requested by server; consi ...

  8. 安装PostgreSQL数据库(Linux篇)

    0.编译环境 Linux: CentOS 5.5 gcc: 4.1.2 1. 安装PostgreSQL 1) 解压postgresql-9.1.7.tar.bz2 #tar jxvf postgres ...

  9. public void与public static void区别

    我们换个简单易懂的说法,这两句的区别就在于,能不能直接用类名访问. 很好理解的不是吗? 假如,我有一个类,如下图所示: 接下来先实例化一个对象,ca,你会发现它不仅可以访问普通的方法,也可以访问静态的 ...

  10. iconMoon---小图标小记

    IcoMoon 是一个免费的图标库.可以下载自己需要的图标 三.使用流程.操作演示 进入主页,点击下图所示区域开始: 每个图标你都是可以自己进行标记的(移上去会看到Edit, 点击之),然后—— 注: ...