JAVA语言程序设计 第8版 复习题2.13 求高人指点

Tian3seawolf 2015-02-07 11:55:15
这是题目要求 这是我按照题目要求编写的代码


import java.util.Scanner;

public class ComputeFutureInvestmentValue
{

public static void main(String[] args)
{
// Create an new Scanner
Scanner input=new Scanner(System.in);

//提示输入投资总额
System.out.print("Enter investement amount:");
double investmentAmount=input.nextDouble();

//提示输入月利率
System.out.print("Enter monthly interest rate:");
double monthlyInvestmentRate=input.nextDouble();

//提示输入投资年限
System.out.print("Enter number of years:");
Integer numberOfyears=input.nextInt();

//计算未来的投资额
double futureInvestmentValue=investmentAmount*(Math.pow(1+monthlyInvestmentRate, numberOfyears*12));
//计算年利率
//double annualInterestRate=monthlyInvestmentRate*12;
//double futureInvestmentValue=investmentAmount*(Math.pow(1+annualInterestRate,numberOfyears));

//输出结果
System.out.println("Accumulated value is :" + " " +futureInvestmentValue);


}

}



但是按照书上说的输入后显示

红圈中的结果与书上的却不一样
求高人指点,是程序不对还是书上言之有误!!!!!!!!!!
...全文
245 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tian3seawolf 2015-02-07
  • 打赏
  • 举报
回复
如果是年利率的话就不用 numberOfyears*12
Tian3seawolf 2015-02-07
  • 打赏
  • 举报
回复
monthlyInterestRate月利率的意思
swssa 2015-02-07
  • 打赏
  • 举报
回复
import java.util.Scanner; public class Test{ public static void main(String[] args){ // Create an new Scanner Scanner input=new Scanner(System.in); //提示输入投资总额 System.out.print("Enter investement amount:"); double investmentAmount=input.nextDouble(); //提示输入月利率 System.out.print("Enter annual interest rate:"); double annualInvestmentRate=input.nextDouble()*0.01; //提示输入投资年限 System.out.print("Enter number of years:"); Integer numberOfyears=input.nextInt(); //计算未来的投资额 double futureInvestmentValue=investmentAmount*Math.pow(1+annualInvestmentRate/12, numberOfyears*12); //计算年利率 //double annualInterestRate=monthlyInvestmentRate*12; //double futureInvestmentValue=investmentAmount*(Math.pow(1+annualInterestRate,numberOfyears)); //输出结果 System.out.printf("Accumulated value is : %.2f",futureInvestmentValue); } } 题目让输入的应该是年利率吧。
Tian3seawolf 2015-02-07
  • 打赏
  • 举报
回复
那在这个程序上怎么改呢 高人!!!!
skgary 2015-02-07
  • 打赏
  • 举报
回复
没加本金,没格式化。

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧