• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parsing and tokenizing  RSS feed

 
Daniel Curtis
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm trying to write a program that will take the input: 56 31.23 false 984 and output 56984 using parsing and tokenizing techniques. So far this is what I have:

The program seems to be running in a loop and I can't figure out why. The prompt for "Input int" isn't working either. Any help would be appreciated to have the program output 56984. Thanks.

(Moderator edit: added code tags to improve readability)
 
Junilu Lacar
Sheriff
Posts: 11486
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daniel,

Welcome to the Ranch!

Please use code tags around code snippets to make them more readable and preserve indentation. One suggestion on how to find a problem on a program that's as small as this: back everything out and start stepping in one thing at a time. For example, first try to output a prompt. Run the program. Once that works as you want it to, try adding the scanner input and display what it gets with good input values. Don't put that in a loop yet. Once you get that working, try running the program with bad input. Get it to work as you want. Then, at the very end, put the appropriate parts of the working code in a loop. When you incrementally build up your program like this, just adding on little by little to already working code, you know exactly what change is causing the program to not work anymore.

Good luck.
 
Daniel Curtis
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply. I narrowed the problem down to where my prompt was. I have the program producing the correct output of: 56984 when I enter : 56 31.23 false 984. Now the only problem I'm having is that the program never exits =( I know this has something to do with the while loop and hasNext() method, but I do not understand the logic. Here is what I have now:


So I guess my question is why is the program not exiting after the output? Thanks!
 
Junilu Lacar
Sheriff
Posts: 11486
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are lines 17, 18, 21, and 22 supposed to be doing? Did you check what the values of nfe.toString() and ime.toString() actually are? Will the condition for exiting the loop ever be met?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Curtis wrote:So I guess my question is why is the program not exiting after the output?

Almost certainly because the stream isn't ended.

Try typing Ctrl+Z (on Windows, the equivalent on Unix/Linux is usually Ctrl+D, but I don't know if Java recognizes it or not); that'll send an "end-of-stream" marker.

Winston
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!