目录
一、程序运行截图
二、注意
1、在输出时,使用原始c语言的printf写法
2、使用了针对string类型的format方法,%.4f表示保留小数点后四位
3、使用了Math类,里面包含各种数学常用符号,包括自然对数e,圆周率PI等等(这里Math.E表示自然对数,其它使用请自行查询)
三、代码
import java.util.Scanner;
public class fenduan {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double x = in.nextDouble();
double y = 1;
if(x>0){
y = Math.pow(Math.E, -x);
}
else if(x<0){
y = -Math.pow(Math.E, x);
}
System.out.printf("y=" + String.format("%.4f", y));
in.close();
}
}