Java:用户输入 Antilog Base 问题?

标签 java

我正在寻找输入值的反对数。使用自然对数基数答案将是正确的。但是当尝试使用输入基数找到反对数时。然后它不会给出正确的答案,例如
以 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/

相关文章:

java - 在 Java 中将 PDF 文件内容转换为 Base 64,反之亦然

java - 如何监控文件上传进度?

java - 共享首选项用户名

java - Maven jersey-multipart 缺少对 javax.ws.rs.core.Response 的依赖

java - getChildNodes() 返回的 DOM NodeList 的顺序

Java:从字节到字符的转换以及如何使用dataOutputStream

java - Hibernate版本的jar,maven,应该一起放什么?

java - 可以在 quartz 中使用不同的触发器运行相同的作业吗?

java - 元数据异常 : The type "*.CustomerEntity" has not been enhanced - whentrying to create row with Spring-JPA and OpenJPA

java - 创建新模型和 View 或将模型作为方法参数传递有什么区别