-10
for(int i=0; i<=years; i++; finall=money+returnn;)

{
      System.out.println(finall);
}

出于某种原因,netbeans 说我在某个地方需要一个“)”?我不知道怎么了

4

2 回答 2

7

You shouldn't put a ; after finall=money+returnn. Also your for loop has too many parts. It should have 3 (initialization, stop condition, modifier) while you have 4 parts.

If you really want multiple actions in one of those parts though, it is possible by separating them using , (so not ;). In this case though, it would be better to put finall=money+returnn inside the loop since it doesn't have anything to do with stopping your loop.

于 2013-06-05T15:24:40.227 回答
7

You have 3 parts in a for loop: initialization, condition and increment. You are defining one more with finall=money+returnn;

You can put several incrementations, but separated with commas:

for(int i=0; i<=years; i++, finall=money+returnn)

but for each loop (different value of i) you will apply all the statements in the last part of the loop.

于 2013-06-05T15:25:25.413 回答