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 |
Hi friends am new to java. I read jar file means collection of java files. For executing struts application what are the necessary jar files. " struts.jar " file contains what. can u explain
How can you sort dates?
What is treeset in java?
What are the two ways to create a thread?
What is singleton math?
What is lazy activation?
why using interface interface ?
What is user defined exception in Java?
What is Restrictions in hibernate?
What are different types of arrays?
Can an object?s finalize() method be invoked while it is reachable?
Can I overload to string method