Java中Math类

来源:互联网 发布:印刷晒版用什么软件 编辑:程序博客网 时间:2024/06/02 02:06
package rj141s;

public class Test01 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        System.out.println("Math.abs()方法返回绝对值,类型可以是double、long、float、int等:"
                +Math.abs(-55.6256));
        System.out.println("Math.PI的值:"+Math.PI);
        
        //public static double acos(double a);-1.0为π, 1为0
        //public static double asin(double a);返回一个角度的反正弦,从-pi/2到pi/2
        //public static double atan(double a)返回一个角的反正切,在到pi / 2,-π/ 2的范围内
        //public static double atan2(a,b)该方法通过计算y/x反正切-pi到pi的范围内计算theta。
        //到极性相关(r, theta)转换为矩形坐标(x,y)。
        System.out.println("三角形");
        System.out.println("Math.acos()的值:"+Math.acos(0.5));
        System.out.println("Math.asin()的值:"+Math.asin(0.5));
        System.out.println("Math.atan()的值:"+Math.atan(0.5));    
        System.out.println("Math.atan2()的值:"+Math.atan2(1, 2));
        System.out.println("Math.cos()的值:"+Math.cos(1));
        System.out.println("Math.sin()的值:"+Math.sin(1));
        System.out.println("Math.tan()的值:"+Math.tan(1));    
        System.out.println("Math.cosh()的值:"+Math.cosh(1));
        System.out.println("Math.sinh()的值:"+Math.sinh(1));
        System.out.println("Math.tanh()的值:"+Math.tanh(1));
        
        System.out.println("Math.cbrt()方法是返回它的立方根  "
                +Math.cbrt(-8));
        System.out.println("Math.ceil()方法是返回接近它最大的值  "
                +Math.ceil(5.23));
        System.out.println("Math.floor()方法是返回接近它最小的值  "
                +Math.floor(5.63));
        System.out.println("Math.ceil()方法是返回它四舍五入的值  "
                +Math.rint(5.23));
        System.out.println("Math.exp()方法,高等数学里以自然常数e为底的指数函数。返回它次幂的值 : "
                +Math.exp(0));
        System.out.println("Math.expm1()方法,计算方法e^a -1。值为:  "
                +Math.expm1(0));
        //public static double hypot(double a,double b);
        System.out.println("Math.hypot()方法,计算Math.sqrt(x^2+y^2);值为:"
                +Math.hypot(3, 4));
        System.out.println("Math.sqrt()方法,返回其平方根。值为: "
                +Math.sqrt(4));
        
        System.out.println("Math.log10()方法,以自然常数10为底的指数函数。值为: "
                +Math.log10(10));
        System.out.println("Math.max()方法,返回大的那个。值为: "
                +Math.max(5, 1.2));
        System.out.println("Math.min()方法,返回小的那个。值为: "
                +Math.min(5, 1.2));
        System.out.println("Math.round()方法,向下转型。值为: "
                +Math.round(55.6));
        System.out.println("Math.signum()方法,0得0,大于0得1.0,小于0得-1.0。值为: "
                +Math.signum(5));
        System.out.println("Math.toDegrees()方法,弧测度-->角测度。值为: "
                +Math.toDegrees(2));
        System.out.println("Math.toRadians()方法,角测度-->弧测度。值为: "
                +Math.toRadians(58));
        System.out.println("Math.ulp()方法。返回ulp的大小的参数。ulp双重价值的积极" +
                "的浮点值和双值之间的距离下一个更大的大小。值为: "
                +Math.ulp(55.9905));
        System.out.println("Math.copySign()方法。返回第一个参数,第二个参数的符号。值为:"
                +Math.copySign(22.5, -8));
        System.out.println("Math.scalb(a, b)方法。计算a*2^b。值为:"
                +Math.scalb(2, 2));
        
    }

}


0 0
原创粉丝点击