
write a java program that continuously prints HelloWorld! to the screen(once every second ) and exists when press the enter key

Hi Friend,
Try the following code:
public class DisplayMessageContinuously extends Thread {
private String st;
private long delay;
public DisplayMessageContinuously(String st, long delay) {
this.st = st;
this.delay = delay;
setDaemon(true);
}
public static void main(String[] args) {
Thread th = new DisplayMessageContinuously("Hello World ", 1000);
th.start();
try {
System.in.read();
System.out.println("Enter pressed...\n");
} catch (Exception e) {
System.out.println(e);
}
return;
}
public void run() {
try {
while(true) {
System.out.println(st);
sleep(delay);
}
} catch(Exception e) {
System.out.println(e);
}
}
}
Thanks

Thanks

Thanks