0
所以我是一个初学者,你可以告诉我,我目前正在尝试理解参数,并想知道我是否正确地做了这个。该程序的工作原理,但我不想让它格式错误,或者我没有理由使用它们,因为参数(?)不会改变。我们目前正在研究参数,所以我想我会试一试,并尝试将其纳入本作业。我使用了正确的参数吗?
import java.util.Scanner;
public class Investments
{
public static void main(String []args)
{
double investment,interestRate, futureValue;
Scanner keyboard = new Scanner(System.in);
System.out.println("What is the investment amount?");
investment = keyboard.nextDouble();
System.out.println("What is the interest rate?");
interestRate=keyboard.nextDouble();
futureValue = investment * (Math.pow(1+interestRate, 5));
futureValue = investments(futureValue);
System.out.println("Your investment afer 5 years:" + futureValue);
futureValue = investment * (Math.pow(1+interestRate, 10));
futureValue = investments(futureValue);
System.out.println("Your investment after 10 years:" + futureValue);
futureValue = investment * (Math.pow(1+interestRate, 20));
futureValue = investments(futureValue);
System.out.println("Your investment after 20 years:" + futureValue);
}
public static double investments (double futureValue)
{
double result;
result = Math.round(futureValue * 100);
result = result/100;
return result;
}
}
你试过编译并运行它,那是要检查的最佳途径,如果你的代码工作:-) ?对我来说似乎没问题。 – ctst
感谢赞赏反馈。我确实运行它,它的工作原理!我只需要知道我是否做得正确 –