counter - Using \r in Java for Count Down Timer -
how use \r in java count down timer? want count down 20 0 , print this, want update instead of writing in new line used \r . works, when comes 10, after this, instead of writing 9 writes 90, 80 , on... plz update code solve problem. here code
int timer1=20; int timer2=0; string timer3="\r"; while(timer1>timer2){ try {thread.sleep(1000);} catch (interruptedexception e) {e.printstacktrace();} system.out.print(timer3+timer1); system.out.flush(); timer1--;}
your variable names ae confusing least. problem having \r taking start of line , not overwriting previous output when write out number 9 still left 0 10.
change line:
system.out.print(timer3+timer1);
to:
system.out.print(timer3+timer1+ " ");
and should fix things.
Comments
Post a Comment