我试图在数组中加倍。问题是我必须将用户输入的结果存储在数组中。例如,我向用户询问初始人口、第一天和增长率。然后计算人口增长。我打算将增加的人口存储在一个数组中,有人可以帮忙吗?卡住。这是我的代码:
public static void main(String[] args) {
Scanner kd = new Scanner(System.in);
double tempPop, tempRate;
int tempDay;
double growth;
System.out.println("Enter Population: ");
tempPop = kd.nextDouble();
System.out.println("Enter Days: ");
tempDay = kd.nextInt();
System.out.println("Enter Rate: ");
tempRate = kd.nextDouble();
final double SCORES = tempDay;
double scores [] = new double[(int) SCORES];
for(int i = 0; i < SCORES; i++)
{
scores[i] = getRate(tempPop, tempDay, tempRate);
System.out.println(scores[i]);
}
}
public static double getRate(double tempPop, int tempDay, double tempRate)
{
double popul, pops = 0;
for (double day = 0; day <= tempDay; day++)
{
popul = tempPop + (tempPop * tempRate/100);
pops = day*popul;
}
return pops;
}
}
这是我的输出:(仅示例)
Enter Population:
10
Enter Days:
2
Enter Rate:
3
10.3
10.3