用import java.lang.math.;_显示声明的java.lang.Math方法

本文介绍了如何使用Java反射API获取`java.lang.Math`类的所有公开方法,包括abs(), sin(), cos(), 等,并展示了实际操作的代码示例。这些方法涵盖了基本算术、三角函数和数值计算等功能。
摘要由CSDN通过智能技术生成

可以使用java.lang.Class.getDeclaredMethods()方法列出java.lang.Math类的方法。

此方法返回一个数组,其中包含具有公共,私有,受保护和默认访问权限的所有Method对象。但是,不包括继承的方法。另外,getDeclaredMethods()如果类或接口没有方法,或者在Class对象中表示原始类型,数组类或void ,则该方法返回零长度数组。

演示此的程序如下所示-

示例import java.lang.reflect.Method;

public class Demo {

public static void main(final String[] args) {

final Method[] methods = Math.class.getDeclaredMethods();

System.out.println("Methods of java.lang.Math Class\n");

for (int i = 0; i 

System.out.println("The method is: " + methods[i]);

}

}

}

输出结果Methods of java.lang.Math Class

The method is: public static int java.lang.Math.abs(int)

The method is: public static double java.lang.Math.abs(double)

The method is: public static float java.lang.Math.abs(float)

The method is: public static long java.lang.Math.abs(long)

The method is: public static double java.lang.Math.sin(double)

The method is: public static double java.lang.Math.cos(double)

The method is: public static double java.lang.Math.tan(double)

The method is: public static double java.lang.Math.atan2(double,double)

The method is: public static double java.lang.Math.sqrt(double)

The method is: public static double java.lang.Math.log(double)

The method is: public static double java.lang.Math.log10(double)

The method is: public static double java.lang.Math.pow(double,double)

The method is: public static double java.lang.Math.exp(double)

The method is: public static long java.lang.Math.min(long,long)

The method is: public static double java.lang.Math.min(double,double)

The method is: public static float java.lang.Math.min(float,float)

The method is: public static int java.lang.Math.min(int,int)

The method is: public static double java.lang.Math.max(double,double)

The method is: public static float java.lang.Math.max(float,float)

The method is: public static long java.lang.Math.max(long,long)

The method is: public static int java.lang.Math.max(int,int)

The method is: public static long java.lang.Math.addExact(long,long)

The method is: public static int java.lang.Math.addExact(int,int)

The method is: public static long java.lang.Math.decrementExact(long)

The method is: public static int java.lang.Math.decrementExact(int)

The method is: public static long java.lang.Math.incrementExact(long)

The method is: public static int java.lang.Math.incrementExact(int)

The method is: public static int java.lang.Math.multiplyExact(int,int)

The method is: public static long java.lang.Math.multiplyExact(long,long)

The method is: public static long java.lang.Math.negateExact(long)

The method is: public static int java.lang.Math.negateExact(int)

The method is: public static int java.lang.Math.subtractExact(int,int)

The method is: public static long java.lang.Math.subtractExact(long,long)

The method is: public static double java.lang.Math.scalb(double,int)

The method is: public static float java.lang.Math.scalb(float,int)

The method is: public static float java.lang.Math.copySign(float,float)

The method is: public static double java.lang.Math.copySign(double,double)

The method is: public static int java.lang.Math.getExponent(double)

The method is: public static int java.lang.Math.getExponent(float)

The method is: public static double java.lang.Math.signum(double)

The method is: public static float java.lang.Math.signum(float)

The method is: public static double java.lang.Math.asin(double)

The method is: public static double java.lang.Math.acos(double)

The method is: public static double java.lang.Math.atan(double)

The method is: public static double java.lang.Math.toRadians(double)

The method is: public static double java.lang.Math.toDegrees(double)

The method is: public static double java.lang.Math.cbrt(double)

The method is: public static double java.lang.Math.IEEEremainder(double,double)

The method is: public static double java.lang.Math.ceil(double)

The method is: public static double java.lang.Math.floor(double)

The method is: public static double java.lang.Math.rint(double)

The method is: public static long java.lang.Math.round(double)

The method is: public static int java.lang.Math.round(float)

The method is: public static double java.lang.Math.random()

The method is: public static int java.lang.Math.toIntExact(long)

The method is: public static int java.lang.Math.floorDiv(int,int)

The method is: public static long java.lang.Math.floorDiv(long,long)

The method is: public static int java.lang.Math.floorMod(int,int)

The method is: public static long java.lang.Math.floorMod(long,long)

The method is: public static float java.lang.Math.ulp(float)

The method is: public static double java.lang.Math.ulp(double)

The method is: public static double java.lang.Math.sinh(double)

The method is: public static double java.lang.Math.cosh(double)

The method is: public static double java.lang.Math.tanh(double)

The method is: public static double java.lang.Math.hypot(double,double)

The method is: public static double java.lang.Math.expm1(double)

The method is: public static double java.lang.Math.log1p(double)

The method is: public static double java.lang.Math.nextAfter(double,double)

The method is: public static float java.lang.Math.nextAfter(float,double)

The method is: public static double java.lang.Math.nextUp(double)

The method is: public static float java.lang.Math.nextUp(float)

The method is: public static double java.lang.Math.nextDown(double)

The method is: public static float java.lang.Math.nextDown(float)

The method is: static double java.lang.Math.powerOfTwoD(int)

The method is: static float java.lang.Math.powerOfTwoF(int)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值