When I make a Java code like:
for (int iRun = 0; iRun <nRun; iRun++){
doSomething();
if (100 < nRun && iRun % (nRun / 100) == 0)
System.err.print("\rWorking " + Math.ceil(100.0 * iRun / nRun) + "%");
}
System.err.println("\rWorking " + Math.ceil(100.0 * iRun / nRun) + "%");
System.err.println("fin");
, it sometime returns
Working 100.0%
fin
, bot not always... it also prints
Working 100.0%Working 100.0%
fin
.
I do not think, in my codes, any thread calls System.err#println
at the time.
Even if I put in Thread.sleep(100);
, it often prints Working 100.0%
twice. I did not try over 100 sec.(I am not sure it really works and further.... what I tried is not bad..)
How can I make sure that the code prints the first way only??
and if there is a certain answer, it can be used for System.out::println
as well?