Timing/Animating Text in Java

I want to animate/time a few dots so they appear on the screen one-by-one. Here’s my code:

else {
            System.out.print("Skipping the temperature check");
            System.out.print(".");
            System.out.print(".");
            System.out.print(".");
        }

I want the “Skipping the temperature check” line to be printed out first, and then the dots to appear one-by-one. Is there any way to do this?

Answer

you can use thread sleep and new line character as below

System.out.print("Skipping the temperature check n");
        Thread.sleep(1000);
        System.out.print(". n");
        Thread.sleep(1000);
        System.out.print(". n");
        Thread.sleep(1000);
        System.out.print(". n");
        

Leave a Reply

Your email address will not be published. Required fields are marked *