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 quick sort in java?
What is JAVA? Why it is platform independent?
What is the inheritance?
What is meant by overloading?
How do you remove duplicates from an array in java?
take an array with -ve and +ve value both.find out the nearest value of 0(zero).if two values are same like(-2 and +2)then extract +2 is nearest of 0(zero).
what is Remote Reference Layer ?
For class CFoo { }; what default methods will the compiler generate for you>?
What are the steps involved to create a bean?
When should you use arraylist and when should you use linkedlist?
How is Object Oriented Programming different from Procedure Oriented Programming?
What is the top class of AWT event hierarchy?