java - 数学难度

标签 java pow

当我输入 1000 投资金额 4.25 月利率和 1 年,为什么我得到的结果是 4.384414858452464E11 而不是预期的 1043.34?

import java.util.Scanner;

public class FinancialApplicationFutureInvestment_13 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter investment amount: ");
        int investmentAmount = input.nextInt();
        System.out.println("Enter monthly interest rate: ");
        double monthlyInterestRate = input.nextDouble();
        System.out.println("Enter number of years");
        int numOfYears = input.nextInt();

        double futureInvestmentValue = investmentAmount *
            (Math.pow(1 + monthlyInterestRate, numOfYears * 12));
        System.out.println("Accumulated value is: " + futureInvestmentValue);

        double test = Math.pow(1 + monthlyInterestRate, numOfYears * 12);
        System.out.println(test);
    }
}

最佳答案

月利率可能需要输入 0.0425

关于java - 数学难度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11359160/

相关文章:

java - Proguard - Unresolved 对程序类成员的引用

java - 两个动画之间有 1 秒的延迟

php - php中的幂函数计算17^2147482999

java - 有人能解释一下舍入误差是什么意思吗?

c++ - 奇怪的 pow(x, y);行为

c - 乘以和增加战俘

java - 为什么 math.pow 本身不能处理整数? (地板/天花板也是)

java - 用GSON解析JSON,对象有时包含列表有时包含对象

java - 从 java.util.Date 转换为 java.sql.Timestamp 的问题

内存泄漏的java堆和线程分析