Java 数学练习没有给出正确答案
Java Math Exercise Not Giving Right Answer
7 - 2 + Math.log10(1000) + Math.log(Math.pow(Math.E, 5))
这在 Java 中有什么意义我不能插入它,因为如果我在 class/method 中编译它,即使它检查是好的,它也会给我错误。我不确定我做错了什么,因为我得到了 10.171 和更多的数字,但它仍然说我在网上练习错了 - 它。我知道 7 - 2 + Math.log10(1000) 最终等于 8 但我只是在添加的最后一部分搞砸了因为我不确定 Math.E 是 5 的幂和 log 时的值.
final
部分 不是 问题:
public class MathCode {
public static final double x1 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
public static double x2 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
private static double x3 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
private final double x4 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
public final double x5 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
private double x6 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
public double x7 = 7 - 2 + Math.log10(1000) + Math.log(Math.pow(Math.E, 5));
public static void main(String... args) {
final MathCode mathCode = new MathCode();
final double x8 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
double x9 = 7 - 2 + Math.log10(1000) + Math.log(Math.pow(Math.E, 5));
System.out.println("x1: " + x1);
System.out.println("x2: " + x2);
System.out.println("x3: " + x3);
System.out.println("x4: " + mathCode.x4);
System.out.println("x5: " + mathCode.x5);
System.out.println("x6: " + mathCode.x6);
System.out.println("x7: " + mathCode.x7);
System.out.println("x8: " + x8);
System.out.println("x9: " + x9);
}
}
下面的结果是:
x1: 13.0
x2: 13.0
x3: 13.0
x4: 13.0
x5: 13.0
x6: 13.0
x7: 13.0
x8: 13.0
x9: 13.0
尝试使用 Math.exp(5)
而不是 Math.pow(Math.E,5)
这个运行并给出了13
的输出
public class MathTest{
public static void main(String[] args){
System.out.print( 7 - 2 + Math.log10(1000) + Math.log(Math.pow(Math.E, 5)) );
}
}
7 - 2 + Math.log10(1000) + Math.log(Math.pow(Math.E, 5))
这在 Java 中有什么意义我不能插入它,因为如果我在 class/method 中编译它,即使它检查是好的,它也会给我错误。我不确定我做错了什么,因为我得到了 10.171 和更多的数字,但它仍然说我在网上练习错了 - 它。我知道 7 - 2 + Math.log10(1000) 最终等于 8 但我只是在添加的最后一部分搞砸了因为我不确定 Math.E 是 5 的幂和 log 时的值.
final
部分 不是 问题:
public class MathCode {
public static final double x1 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
public static double x2 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
private static double x3 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
private final double x4 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
public final double x5 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
private double x6 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
public double x7 = 7 - 2 + Math.log10(1000) + Math.log(Math.pow(Math.E, 5));
public static void main(String... args) {
final MathCode mathCode = new MathCode();
final double x8 = 7 - 2 + Math.log10(1000)
+ Math.log(Math.pow(Math.E, 5));
double x9 = 7 - 2 + Math.log10(1000) + Math.log(Math.pow(Math.E, 5));
System.out.println("x1: " + x1);
System.out.println("x2: " + x2);
System.out.println("x3: " + x3);
System.out.println("x4: " + mathCode.x4);
System.out.println("x5: " + mathCode.x5);
System.out.println("x6: " + mathCode.x6);
System.out.println("x7: " + mathCode.x7);
System.out.println("x8: " + x8);
System.out.println("x9: " + x9);
}
}
下面的结果是:
x1: 13.0
x2: 13.0
x3: 13.0
x4: 13.0
x5: 13.0
x6: 13.0
x7: 13.0
x8: 13.0
x9: 13.0
尝试使用 Math.exp(5)
而不是 Math.pow(Math.E,5)
这个运行并给出了13
的输出public class MathTest{
public static void main(String[] args){
System.out.print( 7 - 2 + Math.log10(1000) + Math.log(Math.pow(Math.E, 5)) );
}
}