Console program for making time appear on the same position
First your title is misleading, please read what Recursion means.
What you need to do is to override the curret line with the new time. This is done in a console programm by using the the carriage return charcter \r
(to go back one character you can use the backspace character \b
)
You could try something like this (Note that for this to work you must not print a new line charachter \n
at the end of your line ):
import java.text.SimpleDateFormat;
import java.util.Date;
public class Time {
public static void main(String... args) throws InterruptedException {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
while(true) {
System.out.printf("\r%s", sdf.format(new Date()));
Thread.sleep(1000);
}
}
}