简体   繁体   English

我如何把它放在一个 for 循环中

[英]How do I put this in a for-loop

I would like to put the following to a for loop.我想将以下内容放入 for 循环。 How do I do this since we haven't studied arrays yet.由于我们还没有研究数组,我该怎么做。 My instructor would like me to put the quarters 1-4 to a for loop.我的导师希望我将第 1-4 节放入 for 循环。

quarter = 1;
interest = principal * quarterlyRate; // item 5
finalAmount = principal + interest;
System.out.printf("%6s%8d%16.2f%30.2f%n", year, quarter, interest, finalAmount);```

Maybe this is what you want:也许这就是你想要的:

# looping here
for (int i=0; i<4; i++) {
   interest = principal * quarterlyRate; // item 5
   finalAmount = principal + interest;
   System.out.printf("%6s%8d%16.2f%30.2f%n", year, i, interest, finalAmount);```
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM