Hi guys, this is my first post and first time joining a forum. I'm a beginner in the Java world and was hoping that someone might be able to help me out. I've been working through a book called Learn Java the Hard Way which was all going well until I got to an exercise that involved getting input from the user. The program was compiled perfectly and ran initially. I have the code exactly as it is in the book (my eyes are almost bleeding from checking and double checking) so I can't work out where I've went wrong. When the program runs the first question that comes up is: "What city is the capital of France?" which then the user should be able to type their answer, hit enter then the next question comes up. The problem is I cannot input anything whatsoever or hit enter to move on. I have included the code:
Cheers and hopefully it could help someone else as well.
Thanks for both replies. Both helpful I appreciate it and next time there will be code tags!
Now here's the news, I've been running all the programs for the previous exercises on Powershell. This one has been the only one where I haven't been able to get it running. I fired up Command Prompt and tried. It is working absolutely fine. I'm sure I sound like a clampit. I'm trying to stick to exactly everything in the book where it recommended powershell, so I don't get ahead of myself. Is this the norm then or does Powershell not run certain programs? Strange. Cheers
You know that you are getting input from the Scanner, but you appear not to be using it?
Thanks! Aye, it's all good now. I think I needed to look away from the screen for a minute then look back and see the problem! I needed to run it in Command Prompt. Working perfect now. On to the next Exercise Cheers
The problem is I cannot input anything whatsoever or hit enter to move on.
This is serious. You cannot input anything nor hit the enter key? Your code as it is will compile fine and run fine if the inputs are in line with those required. Otherwise it will throw an exception.
Hi Paul, I appreciate your help. I was thinking the same thing, there would have been an exception had there been a problem with the code. It turned out I was running it in the wrong place. Thanks!
posted 6 years ago
It turned out I was running it in the wrong place. Thanks!
You are welcome. A good way of learning from examples is to try to tweak them to meet new requirements. For instance, you could save the inputs in variables, print output to screen and handle possible errors. I wish you good continuation!
I am always surprised at the added knowledge i can get from others when i give my opinion on a topic.