我正在尝试循环一个数组,以便它将根据方程存储一个数字。方程中使用下一个元素的位置。 (抱歉,如果这不能很好地解释它)但这里有一个例子。 A=10-1,B=A-1,C=B-1。希望这能澄清一点。
BufferedReader br = new BufferedReader
(new InputStreamReader(System.in));
int tryAgain =1;
double[]arrayYear = new double[41];
System.out.println("DECLINING ATTENDANCE");
System.out.println("=====================");
System.out.println("Attendance has been decreasing steadily at weekly religious services from\n1985. This program will dislpay the percentage of the Canadian population that\nattends a weekly religious service, from any year from 1985-2025.");
for (int i = 0; i <=40; i ++){
arrayYear[i] = 30-0.45;}
最佳答案
arrayYear[i] = 30 - 0.45 * i;
或者,为了更准确:
arrayYear[i] = 30 - 45 * i / 100.0;
关于java - 循环数组以存储使用前一个元素的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27496216/