第一个打印0和第二个打印1。我需要更改什么才能使第二个打印0?
我尝试使用
System.out.println("SMALL LOOP COUNT = " + smallCountLoopCount);
括号来尝试确保数学正确流动,然后先执行乘法,然后再进行第二次。 看起来加法器正在增加变量而不是使用数学?
()
预期结果:
while (bigCountLoopCount <= bigCount) {
//System.out.println(bigCountLoopCount + " " + smallCountLoopCount);
if ((bigCountLoopCount * 5) == goal) {
//System.out.println("THIS TRUE ACTIVATED");
return true;
}
System.out.println("SMALL LOOP COUNT = " + smallCountLoopCount);
if (((bigCountLoopCount * 5) + smallCountLoopCount) == goal)
{
System.out.println("SMALL LOOP COUNT = " + smallCountLoopCount);
System.out.println("THIS TRUE ACTIVATED by:");
System.out.println(bigCountLoopCount + " " + smallCountLoopCount + " " + goal);
return true;
}
smallCountLoopCount++;
bigCountLoopCount++;
}
SMALL LOOP COUNT = 0
SMALL LOOP COUNT = 0
这是因为您在循环主体的末端有
SMALL LOOP COUNT = 0
SMALL LOOP COUNT = 1
。显然,它没有达到任何回报。
如果您更改为smallCountLoopCount++;
和您的循环底部有:
bigCount=0
该条件不会被任何条件包围,因此将始终执行。很难看到您在没有完整代码的情况下要做什么,但是如果您希望SmallCountloopCount保持在零,请删除以下内容:
smallCountLoopCount++;