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

What is meant by packages?

4 Answers  


What is package protected in java?

0 Answers  


What are local variables?

0 Answers  


What is the argument type of main() method?

2 Answers  


What is public static void main?

0 Answers  


Name the package that always imported by default?

4 Answers  


Explain the use of javap tool.

0 Answers  


What is the main method java?

0 Answers  


What is difference between identifier and variable?

0 Answers  


What does the “static” keyword mean?

0 Answers  


How we can make copy of a java object?

0 Answers  


What is the difference between abstraction and encapsulation?

0 Answers  


Categories