public class CountForever { public static void main(String[] args) { for (int i = 1;; i = i + 1) { System.out.println(i); sleep(1000); //one-second pause } } //The following eight lines are needed to get the above sleep to work. static void sleep(long milliseconds) { try { Thread.sleep(milliseconds); } catch (InterruptedException e) { System.err.println(e.getMessage()); } } }