How can i make java update the current console window instead of going onto a new line (or appending new content onto old).
As an example, if i wanted to demonstrate progress, i would output progress n
where n would be the given percentage.
Obviously what i would want to do is simply update n with the current percentage. Any help would be appreciated.
Something like this?
public class Test {
public static void main(String[] args) throws InterruptedException {
for (int i = 0; i < 100; i++) {
System.out.print("\rThinking... " + i);
System.out.flush();
Thread.sleep(100);
}
}
}
It's not guaranteed to work on all consoles of course (some IDEs may struggle), but any that obey "carriage return" (the "\r"
) should be okay.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With