title: How can I replace text that's been printed out on screen already in Java?
body: <p>I'm new to Java and as an attempt to learn more I tried making a clock. It works perfectly, except for the fact that it prints on a new line every time a second changes. How do I make it so that I can replace the text that's already been printed out with the new time?</p>
  
  <pre><code>public class test {
      public static void main(String[] args) {
          test.clock();
      }
      public static void clock() {
          int sec = 0;
          int min = 0;
          int h = 0;
          for(;;) {
              sec++;
              if(sec == 60) {
                  min++;
                  sec = 0;
              } else if(min == 60) {
                  h++;
                  min = 0;
              } else if(h == 24) {
                  h = 0;
              }
              try {
                  Thread.sleep(1000);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              if(h &lt; 10) {
                  System.out.print("0"+h+":");
              } else {
                  System.out.print(h+":");
              }
              if(min &lt; 10) {
                  System.out.print("0"+min+":");
              } else {
                  System.out.print(min+":");
              }
              if(sec &lt; 10) {
                  System.out.println("0"+sec);
              } else {
                  System.out.println(sec);
              }
          }       
      }
  }
  </code></pre>
  
  <p>Here's my code. And here's an example of what I'm trying to do:
  I want to turn this: <code>00:00:00</code>,
  into this: <code>00:00:01</code> (the code does this but it prints on a new line and doesn't delete the old time).
  The thing is that I want to get rid of the first one (<code>00:00:00</code>) and on the same line print the second one (<code>00:00:01</code>).</p>
  
  <p>Is this possible in Java?</p>