Here is one while loop that will iterate 11 times.
public static void main(String[] args) {
int count=0;
while(count<=10){
System.out.print(count);
count++;
}
}
& the output will be definitely : 012345678910
But I want to display the same output in such a way that every iteration will overwrite the previous value while printing the value on console.
Here's the restriction is : We can not use file.
clearing the console on every iteration can be one of the ways, is there anything left we can do?
You can use \r which returns to the start of a line: System.out.print("\r" + count); should work.
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