Math类常用方法

来源:互联网 发布:java 水仙花数 编辑:程序博客网 时间:2024/06/05 19:47
package MathTest;public class MathTest {public static void main(String[] args){/*三角运算*/System.out.println("将1.2弧度转换为角度:" + Math.toDegrees(1.2));System.out.println("将角度90°转换为弧度:" + Math.toRadians(90));System.out.println("计算反余弦0.5,返回值为弧度:" + Math.acos(0.5));System.out.println("计算反正弦0.5,返回值为弧度:" + Math.asin(0.5));System.out.println("计算反正切0.5,返回值为弧度:" + Math.atan(0.5));System.out.println("计算三角余弦" + Math.cos(1.2));System.out.println("计算三角正弦" + Math.sin(1.2));System.out.println("计算三角正切" + Math.tan(1.2));System.out.println("将矩形坐标转换为极坐标:" + Math.atan2(0.1, 0.2));/*取整运算*/System.out.println("-1.2取小于目标数的最大整数:" + Math.floor(-1.2));System.out.println("1.2取大于目标数的最小整数:" + Math.ceil(1.2));System.out.println("2.1四舍五入取整:" + Math.round(2.1));/*乘方、开方、指数运算*/System.out.println("16的平方根:" + Math.sqrt(16));System.out.println("8的立方根:" + Math.cbrt(8));System.out.println("返回欧拉数e的n次幂:" + Math.exp(2));System.out.println("返回sqrt(x^2+y^2):" + Math.hypot(1, 1));System.out.println("对两个参数进行取余运算:" +Math.IEEEremainder(5, 2));System.out.println("计算m的n次幂:" + Math.pow(2, 3));System.out.println("计算自然对数:" + Math.log(Math.E));System.out.println("计算底数为10的对数:" + Math.log10(10));/*符号相关的运算*/System.out.println("-4.1计算绝对值:" + Math.abs(-4.1));System.out.println("将第二个参数的符号给第一个参数:" + Math.copySign(1.2, -1.0));System.out.println("2 符号函数,参数为0返回0,参数大于0返回1.0,小于0返回-1.0: " + Math.signum(2));System.out.println("");/*大小相关的运算*/System.out.println("1.1 - 2.2返回较大值:" + Math.max(1.1, 2.2));System.out.println("1.2返回比目标值略大的浮点数:" + Math.nextUp(1.2f));System.out.println("返回一个在0.0到1.0之间的一个伪随机数:" + Math.random());System.out.println("测试结束");}}

0 0
原创粉丝点击