how to print hello world every second till i have pressed
enter key ???
Answer / core
import java.util.Scanner;
public class InfiniteThread extends Thread {
public void run() {
while (true) {
System.out.println("hi");
try {
this.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) throws InterruptedException {
new ExitThread().start();
new InfiniteThread().start();
}
}
class ExitThread extends Thread{
@Override
public void run() {
Scanner scan = new Scanner(System.in);
String next = scan.nextLine();
if(next.equals(""))
System.exit(0);
super.run();
}
}
Is This Answer Correct ? | 15 Yes | 4 No |
What is remote method invocation (rmi)?
How strings are created in java?
Are the equals() and hashCode() protected methods of object class?
how can you say that java is independ language
What is t type java?
What is an array in java?
What are methods in java?
Can inner class final?
What is the abstraction?
What is ‘has a’’ relationship in java?
What is final, finally, finalize?
What is continuity of a function?