我正在寻找输入值的反对数。使用自然对数基数答案将是正确的。但是当尝试使用输入基数找到反对数时。然后它不会给出正确的答案,例如
以 10 为底的反对数值 10 = 10000000000
这是我的代码:
public class A {
public static void main(String[] args) {
Scanner s = new Scanner(System. in );
double value, res, value2, res2;
System.out.print("Enter Anti Log Value:");
value = s.nextDouble();
res = Math.exp(value);
System.out.println("Answer Of Antilog With natural Base is: + res);
System.out.println("-----------------------------------");
System.out.print("Enter Your Base:");
value2 = s.nextDouble();
res2 = Math.exp(value) / Math.exp(value2);
System.out.println("Answer Of Antilog With your enter Base is : " + res2);
}
}
它给出的答案是输入基数 10 = 1.0 那么如何解决这个问题。
最佳答案
假设我理解你的问题是正确的,你应该简单地替换
res2 = Math.exp(value) / Math.exp(value2);
与
res2 = Math.pow(value2, value);
如果您想在打印值时避免使用科学计数法,请使用:
System.out.printf("Answer Of Antilog With your enter Base is : %f%n", res2 );
或(跳过小数):
System.out.printf("Answer Of Antilog With your enter Base is : %.0f%n", res2 );
关于Java:用户输入 Antilog Base 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30560530/