-4

这可能信息太少......但为什么这与我预期的相反?

                if (indSTime[t] <= monthTotal) {

                    Log.d("indSTime", String.valueOf(indSTime[t++]));
                    Log.d("monthTotal", String.valueOf(monthTotal));

                    NewRate = Double.valueOf(indSRate[s]);
                    indApr[o] = NewRate;
                }

它以大于或等于的方式工作。不小于或等于月份总数。

我将“indSTime”设置为 4。所以 Eclipse 中的 Logcat 开始像这样记录这两个变量。

4, 4
4, 5
4, 6
4, 7

ETC...

似乎应该是

4 ,1
4, 2
4, 3
4, 4

并停止。

我知道我没有在上面添加太多代码?在我面前有什么我想念的东西吗?或者是什么原因造成的?

4

2 回答 2

3

4 is less-than-or-equal-to 4, 5, 6 and 7.

4 is definitely not less-than-or-equal-to 1, 2 or 3.

Why do you think it should be the opposite?

于 2012-05-26T15:10:36.533 回答
3

It's logging entirely reasonable things. Look at your pairings:

Actual:

indSTime=4, monthTotal=4
indSTime=4, monthTotal=5
indSTime=4, monthTotal=6
indSTime=4, monthTotal=7

Expected:

indSTime=4, monthTotal=1
indSTime=4, monthTotal=2
indSTime=4, monthTotal=3
indSTime=4, monthTotal=4

In all of the actual cases, indSTime is less than or equal to monthTotal, exactly as your code suggests.

In your expected output, you've shown three cases where indSTime is greater than monthTotal.

So, either you actually wanted the opposite operator, or you've been confused by your logging, or possibly both. Unfortunately as you haven't shown any context here, it's impossible to say exactly where the problem is - but it's definitely not Java itself.

于 2012-05-26T15:11:24.040 回答