我是靠谱客的博主 难过小蚂蚁,这篇文章主要介绍Java *2.21(财务应用:计算未来投资值)编写程序,读取投资总额、年利率和年数,然后使用下面的公式显示未来投资回报金额:,现在分享给大家,希望可以做个参考。
未来投资回报金额 = 投资总额 x(1+月利率)^ (年数 x 12)
例如:如果输入的投资金额为1000,年利率为3.25%,年数为1,那么未来投资回报金额为1032.98。
下面是一个运行示例:
Enter investment amount(输入投资金额)t:1000.56
Enter annual interest rate in percentage(输入百分比的年利率): 4.25
Enter the number of the years(输入的年数): 1The accumulated value is $1032.98
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18package Chapter_03; import java.util.Scanner; public class Code2_21 { public static void main(String[] args) { System.out.print("Enter investment amount:"); Scanner input = new Scanner(System.in); double amount = input.nextDouble(); System.out.print("Enter annual interest rate in percentage:"); double rade = input.nextDouble() / (100.0 * 12); System.out.print("Enter the number of the years:"); double year = input.nextInt(); double value = amount * Math.pow(1 + rade,year * 12); System.out.println("The accumulated value is $" + String.format("%.2f",value)); } }
输出
复制代码1
2
3
4
5Enter investment amount:1000.56 Enter annual interest rate in percentage:4.25 Enter the number of the years:1 The accumulated value is $1043.92
最后
以上就是难过小蚂蚁最近收集整理的关于Java *2.21(财务应用:计算未来投资值)编写程序,读取投资总额、年利率和年数,然后使用下面的公式显示未来投资回报金额:的全部内容,更多相关Java内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复