Java Math exp()方法用于返回自然數(shù)底數(shù)e的參數(shù)次方。
也就是說,Math.exp(4.0) = e4.0
exp() 方法的語法為:
Math.exp(double a)
注意:exp()方法是靜態(tài)方法。因此,我們可以使用類名Math直接調(diào)用該方法。
a - 要提高e到的數(shù)字
返回自然數(shù)底數(shù)e的參數(shù)次方,即ea
注意:此處,e是歐拉數(shù),其值為2.71828
class Main { public static void main(String[] args) { // Math.exp() 方法 double a = 4.0d; System.out.println(Math.exp(a)); // 54.598150033144236 //不使用Math.exp() //歐拉數(shù)的值 double euler = 2.71828d; System.out.println(Math.pow(euler, a)); // 54.5980031309658 } }
在上面的示例中,我們使用了Math.pow()方法來計(jì)算e 4.0值。在這里,我們可以看到
Math.exp(4.0) = e4.0