1

My \r doesn't work for some odd reason. It won't go back to the start of the line:

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();
        }
    }

}

Output:

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% /
Alexey Gorozhanov
  • 706
  • 10
  • 20
HoverCatz
  • 65
  • 1
  • 5
  • 19

1 Answers1

6

It is the problem of eclipse, it will take \r as a new line character and will print a new line. Try using intellij or from the command line prompt. I just verified in intellij that it works on a Windows

I think this bug must still be unresolved

mistahenry
  • 8,554
  • 3
  • 27
  • 38