【发布时间】:2013-08-20 11:38:24
【问题描述】:
我的问题是基于复利公式。 A = P(1 + r)^n。我有许多 r 和 n 值,我必须将它们存储为数组。我还必须将我的最终值范围 A 也输出为数组。我想我已经将 r 和 n 正确地存储为一个数组。但是我的问题是 A 的最终值并存储每个值 A。到目前为止,这就是我所写的。
import java.util.Scanner;
import javax.swing.*;
public class Prin {
public static void main (String [] args){
System.out.println("Please enter the Principal you wish to invest =>");
Scanner stdio = new Scanner (System.in);
int principal = stdio.nextInt();
stdio.nextLine();
System.out.println("This program will now calculate the final amount A for (years) n = 1,2,3,4 and the rate r = 1%, 1.5%, 2%, 2.5%, 3%");
int yearsarray[] = {1,2,3,4};
double ratearray[] = {0.010, 0.015, 0.020, 0.025, 0.030};
double amountarray[];
amountarray = new double[19];
for(int i=0; i<=3; i++)
{
for(int j=0; j<=5; j++){
amountarray[k] = principal * Math.pow((1 + ratearray[j]), yearsarray[i]);
System.out.println(" answer " + amountarray[k] );
}
}
是否需要另一个 for 循环来增加 amountarray[] 中 k 的值?
我想要amountarray的所有值,即amountarray[0]、amountarray[1]、amountarray[2]、......等等。
提前感谢您的帮助。
【问题讨论】:
-
k = i*5 + j .. 谷歌行大订单:)
标签: java