简体   繁体   English

Java:用户输入Antilog Base问题?

[英]Java:User Enter Antilog Base issue?

I'm finding anti-logarithm of enter values.Answer will be right with natural log base.But when try to find anti-log with enter base.then it doesn't give correct answer such as 我正在寻找输入值的反对数。自然对数的答案是正确的。但是当尝试使用输入对数找到反对数时,它不会给出正确的答案,例如
anti-log value 10 with base 10 = 10000000000
This is my code: 这是我的代码:

    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);
}
}

It give answer with enter base 10 = 1.0 so how to fix this. 输入基数10 = 1.0给出答案,因此如何解决。

Assuming I understand your question correct you should simply replace 假设我理解您的问题正确,那么您只需替换一下

res2 = Math.exp(value) / Math.exp(value2);

with

res2 = Math.pow(value2, value);

If you want to avoid scientific notation when printing the value, use: 如果要在打印值时避免科学计数法,请使用:

System.out.printf("Answer Of Antilog With your enter Base is : %f%n", res2 );

or (to skip the decimals): 或(跳过小数点):

System.out.printf("Answer Of Antilog With your enter Base is : %.0f%n", res2 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM