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 use of session tracking ?with example?
How thread scheduler schedule the task?
what are the oops concept in java explain with real time examples
24 Answers Accenture, Bosch, Consummate Technologies, CTS, Current Technologies, iNautix, Infosys, Kekran Mekran, QA InfoTech, RTRT, SofTech, Tech Mahindra, Thorogood, Timios, Wipro,
Describe the Big-O Notation.
What is character in data type?
What happens when a thrown exception is not handled?
as we know a static method could access static data and static method only. then how could main method call the object of aclass which is not static and other non static data
What is a void return type?
Explain spliterator in java8?
Difference between a MenuItem and a CheckboxMenuItem?
Why is prepared Statement, Callable Statement used for? What is the need of Batch updates?
What are wrapped classes?