1

由于某些奇怪的原因,我的\r不起作用。它不会回到行首:

char[] animationChars = new char[] {'|', '/', '-', '\\'};

public Main() {

    for (int i = 0; i < 100; i++) {
        System.out.print("Processing: " + i + "% " + animationChars[i % 4] + '\r');

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

输出:

Processing: 0% |
Processing: 1% /
Processing: 2% -
Processing: 3% \
Processing: 4% |
Processing: 5% /
Processing: 6% -
Processing: 7% \
Processing: 8% |
Processing: 9% /
Processing: 10% -
Processing: 11% \
Processing: 12% |
Processing: 13% /
Processing: 14% -
Processing: 15% \
Processing: 16% |
Processing: 17% /
4

1 回答 1

6

是eclipse的问题,它会把\r作为换行符,会打印一个新行。尝试使用 intellij 或从命令行提示符。我刚刚在 intellij 中验证它可以在 Windows 上运行

我认为这个错误一定还没有解决

于 2013-07-30T17:32:04.973 回答