首页 > 试题广场 >

(财务应用:计算未来投资值)编写程序,读取投资总额、年利率

[问答题]
 (财务应用:计算未来投资值)编写程序,读取投资总额、年利率和年数,然后使用下面的公式 显示未来投资金顛:
未来投资金额 = 投资总额 X (1+ 月利率)年数12
例如:如果输入的投资金额为1000, 年利率为 3.2SX, 年数为1, 那么未来投资额为1032.98。 下面是一个运行示例:

import java.util.Scanner;
/*
 (财务应用:计算未来投资值)编写程序,读取投资总额、年利率和年数,然后使用下面的公式 显示未来投资金顛:
未来投资金额 = 投资总额 X (1+ 月利率)年数×12
例如:如果输入的投资金额为1000, 年利率为 3.25%, 年数为1, 那么未来投资额为1032.98。 下面是一个运行示例:
 */
public class NKTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter investment amount:");
//        输入投资总额
        double IA = sc.nextDouble();
        System.out.print("Enter annual interest rate in percentage (%):");
//        输入年利率
        double AIRIP = sc.nextDouble() / 100;
        System.out.print("Enter number of years:");
//        输入年数
        int NOY = sc.nextInt();
        sc.close();
//        未来投资金额 = 投资总额 X (1+月利率)^(年数×12) --》 未来投资金额 = 投资总额 X (1+年利率/12)^(年数×12)
        double number = IA * Math.pow(1 + AIRIP/12, NOY * 12);
        System.out.println("Accumulated value is:"+ String.format("%.2f", number));
    }
}
编辑于 2021-05-02 10:11:12 回复(0)
package ab;
import java.util.Scanner;
public class As {
    public static void main(String[] args) {
        double a,b,c;
        System.out.print("Enter investment amount:");
        Scanner in=new Scanner(System.in);
        a=in.nextDouble();
        System.out.print("Enter annual interest rate in percentage:");
        Scanner s=new Scanner(System.in);
        b=s.nextDouble();
        System.out.print("Enter number of years:");
        Scanner m=new Scanner(System.in);
        c=m.nextDouble();
        double d;
        d=a*(1+b);
        System.out.print("Accumulated value is:"+" "+d);
    }

}
好家伙,我不知道它的公式到底写的是啥🤔🤔🤔🤔🤔🤔🤔🤔
发表于 2021-04-08 07:18:25 回复(0)