在java中浅谈Math类中的常用方法
2017-10-19 19:50
435 查看
通过最近的学习,学到了一些的Math类中的常见方法
package org.stm.demo;
public class Test {
}
如果大家有疑问,可评论,也可以到APl中查到相应的用法以及到编辑器里面不妨一试!加油>>>
package org.stm.demo;
public class Test {
public static void main(String[] args) { /** * Math.abs(绝对值) */ System.out.println(Math.abs(-11.8)); //11.8 System.out.println(Math.abs(-0.0)); //0.0 /** * Math.ceil(天花板) */ System.out.println(Math.ceil(-11.8)); //-11.0 System.out.println(Math.ceil(10.8)); //11.0 System.out.println(Math.ceil(-0.6)); //-0.0 System.out.println(Math.ceil(0.0)); //0.0 System.out.println(Math.ceil(-0.0)); //-0.0 /** * Math.floor(地板) */ System.out.println(Math.floor(-11.1)); //-12.0 System.out.println(Math.floor(11.7)); //11.0 System.out.println(Math.floor(-0.7)); //-1.0 System.out.println(Math.floor(0.0)); //0.0 System.out.println(Math.floor(-0.0)); //-0.0 /** * Math.max(arg0,arg1) * Math.min(arg0,arg1) */ System.out.println(Math.max(-11.1, -11)); //-11.0 System.out.println(Math.max(11.7, 11)); //11.7 System.out.println(Math.max(0.0, -0.0)); //0.0 /** * round 四舍五入,float时返回int值,double时返回long值 * Math.round(x) = Math.floor(x+0.5) */ System.out.println(Math.round(10.1)); //10 System.out.println(Math.round(10.7)); //11 System.out.println(Math.round(10.5)); //11 System.out.println(Math.round(10.51)); //11 System.out.println(Math.round(-10.5)); //-10 System.out.println(Math.round(-10.51)); //-11 System.out.println(Math.round(-10.6)); //-11 System.out.println(Math.round(-10.2)); //-10 /** * rint 四舍五入,返回double值 * 注意.5的时候会取偶数 */ System.out.println(Math.rint(10.1)); //10.0 System.out.println(Math.rint(10.7)); //11.0 System.out.println(Math.rint(11.5)); //12.0 System.out.println(Math.rint(10.5)); //10.0 System.out.println(Math.rint(10.51)); //11.0 System.out.println(Math.rint(-10.5)); //-10.0 System.out.println(Math.rint(-11.5)); //-12.0 System.out.println(Math.rint(-10.51)); //-11.0 System.out.println(Math.rint(-10.6)); //-11.0 System.out.println(Math.rint(-10.2)); //-10.0 }
}
如果大家有疑问,可评论,也可以到APl中查到相应的用法以及到编辑器里面不妨一试!加油>>>
相关文章推荐
- Java:Math类中的常用方法
- Java中Math类的常用方法
- Java中Math类的常用方法
- Java第四周常用类与集合框架上机实验二学会Math类常用方法使用
- Java中Math类常用方法总结 + Random类与Math类小结合
- Java中Math类的常用方法
- Java中Math类的常用方法
- Java中Math类的常用方法
- JAVA基础初探(九)Date类、SimpleDateFormat类、Calendar类、Math类(概述及常用方法)
- Java中Math类的常用方法
- java中Math类常用方法
- 《java中Math类定义的常用方法》
- Java中Math类的常用方法
- Java中Math类常用方法代码详解
- Java中Math类的几种常用方法
- JAVA MATH类常用方法
- Java、Android中Math类中常用方法的简单介绍
- java 常用Math类中的方法总结
- Java中Math类常用方法
- Java中Math类的常用方法