我找到了输入值的反对数。答案是正确的,具有自然对数基数。但是当尝试使用输入基数找到反对数时,然后它没有给出正确答案,例如< br {> anti-log value 10 with base 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的答案,所以如何解决这个问题。
答案 0 :(得分:1)
假设我理解你的问题是正确的,你应该简单地替换
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 );