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. MySQL(6)--复制,docker容器中

    MySQL5.7.11实现replication 启动两个安装好mysql的空的docker image ----------------- shell1  master $docker run -i ...

  2. 使用Genymotion调试出现错误INSTALL_FAILED_CPU_ABI_INCOMPATIBLE解决的方法

    今天在使用android studio在Genymotion上调试程序出现INSTALL_FAILED_CPU_ABI_INCOMPATIBLE导致程序安装不了: 后来百度发现是要安装:http:// ...

  3. log Configuration

    Log4j – Configuring Log4j 2 - Apache Log4j 2 https://logging.apache.org/log4j/2.x/manual/configurati ...

  4. dataTables-details 1.9

    本文共四部分:官网 | 基本使用|遇到的问题|属性表 一:官方网站:[http://www.datatables.net/] 二:基本使用:[http://www.guoxk.com/node/jqu ...

  5. VC FTP服务器程序分析(三)

    CControlSocket类的分析,CControlSocket类的内容比较多,为什么呢.因为通信控制命令的传输全部在这里,通信协议的多样也导致了协议解析的多样. 1.OnReceive  其大致说 ...

  6. SQL 和 NoSQL 比较

    定义: SQL (Structured Query Language) 数据库,指关系型数据库.主要代表:SQL Server,Oracle,MySQL(开源),PostgreSQL(开源). NoS ...

  7. SDUT 3035 你猜我猜不猜你猜不猜(字符串 规律性)

    你猜我猜不猜你猜不猜 Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 In the past 39th annual ACM in ...

  8. POJ2728 Desert King —— 最优比率生成树 二分法

    题目链接:http://poj.org/problem?id=2728 Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Subm ...

  9. Navicat——如何导出所有的查询数据

    前言 很简单就是通过Navicat的查询来查询~ 步骤 真的不要太简单了~ 打开Navicat并点击查询 新建查询 选择对应的连接和库 写入SQL并运行 导出结果 1.选择导出当前的结果 2.选择保存 ...

  10. Bug不能重现的原因分析及其对策

    摘 要:本文简要分析了无法重现的Bug的可能产生原因,包括环境不一致.缺少最准确的描述和浏览器的不当设置.针对这些原因,本文给出了相应的对策.通过这些措施,可以重现许多以前认为不可重现的Bug.    ...