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 |
Give me example of derived data types.
Define how can we find the actual size of an object on the heap?
Which sorting algorithm is in place?
Why does abstract class have constructor?
What are jee technologies?
What is entry set in java?
What is difference overloading and overriding?
Where is const variable stored?
Which are the two subclasses under exception class?
What is java literals?
What are access modifiers?
Explain the difference between map and flatmap stream operation?