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 |
Explain the importance of throwable class and its methods?
How finally used under exception handling?
What do you mean by ordered and sorted in collections in java?
Write a program to calculate factorial in java?
What is the purpose of sizeof operator?
What is arrays sort in java?
What modifiers are used for interface declaration?
What is a modifier?
Can u overload main()method.Give with example.
6 Answers IBM, Schimatic Technologies,
What do you mean by exception handling in Java?
what is difference between length and length()?
What is final method?