for (int i = 1; i <= 10; i++) { System.out.println("Line " + i); Thread.sleep(1000); // sleep for 1 second }
for (int i = 10; i >= 1; i--) { System.out.println(i); Thread.sleep(1000); // sleep for 1 second } System.out.println("Blast off!");This example implements a countdown timer that prints out numbers from 10 to 1 with a one-second delay between each print. After the countdown is complete, it prints out "Blast off!". The Thread.sleep() method is part of the java.lang package, which is automatically imported into every Java program.