在java中浅谈Math类中的常用方法
来源:互联网 发布:高三睡不好 知乎 编辑:程序博客网 时间:2024/06/05 16:32
通过最近的学习,学到了一些的Math类中的常见方法
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中查到相应的用法以及到编辑器里面不妨一试!加油>>>
阅读全文
0 0
- 在java中浅谈Math类中的常用方法
- Java Math类中的常用方法
- Java:Math类中的常用方法
- java 常用Math类中的方法总结
- Java中Math类的常用方法
- Java中Math类的常用方法
- Java中Math类的常用方法
- Java中Math类的常用方法
- Java中Math类的常用方法
- Java中Math类常用方法
- JAVA中Math 类的常用方法
- Java中Math类的常用方法
- Java中Math类的常用方法
- Java中Math类的常用方法
- Java中Math类的常用方法
- Java中Math类的常用方法
- Java中Math类的常用方法
- Java中Math类的常用方法
- 2449-数据结构实验之栈与队列十:走迷宫
- 集训Day1 T1 青蛙 (jump)
- 鱼眼镜头的选型
- KMP算法的理解
- 2088-数据结构实验之栈与队列十一:refresh的停车场
- 在java中浅谈Math类中的常用方法
- latex中的箭头
- Xshell中输入rz提示:-bash: rz: command not found
- Oracle连接配置文件 tnsnames
- SQL优化
- 1029. 旧键盘(20)
- 1042. 字符统计(20)
- ajax删除成功后局部刷新
- android中handler简单用法,之前只是复制粘贴的使用,不明白原理,现在补上!