In my opinion, you forget to press “Enter” after entering input. A scanner can read the input if only you press the “Enter” key. Your solution seems correct to me. I was able to properly run it on my PC.
You can find a similar question here:
How to use Scanner to accept only valid int as input
2
solved Cant print the value of scan.nextIn(); [closed]