3

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?

S. Das
  • 75
  • 3
  • 9

1 Answers1

2

You can use \r which returns to the start of a line: System.out.print("\r" + count); should work.

helencrump
  • 1,351
  • 1
  • 18
  • 27