0

このループである種の間違いを犯しましたが、本当にそれを理解できません。ループは次のとおりです。

while (true) {
        System.out.print(stepName[currentTick]);

        for(int i = stepName[currentTick].length() - longestNameInt; i == 0; i--)
            System.out.print(" ");

        System.out.print(" [");

        double percentCalc = (double) stepPercent[currentTick];
        int slotsRep = (int) Math.round((percentCalc * 0.2));

        for(int i = slotsRep; i == 0; i--)
            System.out.print("*");

        for(int i = 20 - slotsRep; i == 0; i--)
            System.out.print(" ");

        System.out.print("] " + stepPercent[currentTick] + "% \r");

        if(currentTick == totalTicks)
            break;

        Thread.sleep(stepTime[currentTick]);
    }

基本的には「(First stepname) [*] 0%」とどんどん出力していきます。当たり前のことで申し訳ありませんが、私は初心者です。:)

PS私のクラスがもっと必要かどうか私に尋ねてください.

4

3 に答える 3

4

これを変更してください:

for(int i = stepName[currentTick].length() - longestNameInt; i == 0; i--)

for(int i = stepName[currentTick].length() - longestNameInt; i >= 0; i--)

比較ミスだけあります。

また、 の値がcurrent tick or totalticks changes for the loop to break等しいことを確認してください。条件が原因で、等値状態に到達せず、ループが無限になる可能性があるためですwhile(true)

于 2013-10-29T05:14:46.040 に答える
1

以下の修正を行います

  1. for(int i = stepName[currentTick].length() - longestNameInt; i >= 0; 私 - )

     2.    `for(int i = slotsRep; i >= 0; i--)
    
      3.  `for(int i = 20 - slotsRep; i == 0; i--)`
    
于 2013-10-29T05:13:15.273 に答える
0

ここに無限whileループがあります。

if(currentTick == totalTicks)
    break;

currentTickどちらの値もtotalTicksまったく変更していないように見えますが、上記の 2 つの値が両方とも等しい場合にbreakfromループが発生するはずです。while最初は等しくなく、 で変更しないためwhile、無限ループになります。

于 2013-10-29T05:15:58.770 に答える