【例11.8】在Java代码中进行指数函数运算
在项目中创建ExponentFunction类,在类的主方法中调用Math类中的方法,实现指数函数的运算,并输出运算结果。
/*【例11.8】在Java代码中进行指数函数运算
* 在项目中创建ExponentFunction类,在类的主方法中调用
* Math类中的方法,实现指数函数的运算,并输出运算结果。
* */
package cylk;
public class ExponentFunction {
public static void main(String[] args) {
// TODO 自动生成的方法存根
//取e的2次方
System.out.println("e的平方值:"+Math.exp(2));
//取以e为底2的对数
System.out.println("以e为底的2的对数:"+Math.log(2));
//取以10为底的2的对数
System.out.println("以10为底的2的对数值:"+Math.log10(2));
//取4的平方根
System.out.println("4的平方根值:"+Math.sqrt(4));
//取8的立方根
System.out.println("8的立方根值:"+Math.cbrt(8));
//取2的2次方
System.out.println("2的2次方值:"+Math.pow(2, 2));
}
}