0

i want to create a simple program in java that ask the user to enter a number (using Scanner) in a countdown, for example 10 sec, and if the user don't enter a number in that amount of time, then the thread will stop and it'll show any message

My problem is that i can't find a way to stop the thread when Scanner.nextInt() is running

Can anybody help me?

Haruk
  • 1
  • Timer and TimerTask are probably better suited to your needs. – MarsAtomic Mar 01 '20 at 05:00
  • 1
    I think you can interrupt thread with interrupt() as normal, but you can't interrupt Scanner (https://stackoverflow.com/questions/4983065/how-to-interrupt-java-util-scanner-nextline-call). Or I misunderstand you. Oh, and you need to start a thread with a countdown before scanner.nextSomething() of course – Hexronimo Mar 01 '20 at 07:34
  • Why do you want a seperate thread for that? Just use a counter and a boolean if the user entered a number. – akuzminykh Mar 01 '20 at 08:54

0 Answers0