Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


how to print hello world every second till i have pressed
enter key ???



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

Post New Answer

More Core Java Interview Questions

Do extraneous variables affect validity?

0 Answers  


what is overloading and overriding with example?

2 Answers   CMC,


Why deletion in linkedlist is fast than arraylist?

0 Answers  


Is java supports multiple inheritance? explain?

12 Answers   BUET, Inforica,


How concurrent hashmap works?

0 Answers  


When should we create our own custom exception classes?

0 Answers  


Is there any way to skip finally block of exception even if some exception occurs in the exception block?

0 Answers  


What is difference overloading and overriding?

0 Answers   Cyient,


what are the rules to use try catch finally?

1 Answers   Satyam, UJ,


What is main in java?

0 Answers  


Can we define a package statement after the import statement in java?

0 Answers  


Difference between the String and StringBuffer classes?

3 Answers  


Categories