This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
We are doing trivial coding as part of an algorithm analysis class and for some reason I can't even get the code down to move on to the next part. Here is my initial while loop to take in a list of integers and add them to an arraylist.
Here is what the console returns when I run what I have so far.
If I type integers and hit enter it will take them as a new input and if I give it non-integer and press enter it ends the loop and moves on. I know I am missing something obvious, but i have been staring at this for like 2 hours and can't figure the problem.
If I type . and hit enter it says false and then 6. Why is it doing this?
With this code I enter "1 2 3 4 5 6 ." and I get returned the correct response. How do I make it so that the user doesn't have to hit space and then period? I remember doing this before but am having a complete memory blanking.
Joined: Jul 08, 2012
After a lot of searching of the google machine I decided to go with reading in the input as a string and then splitting the input and parsing out the integers. In case anyone stumbles across this thread. Thanks.
John Jai wrote:@Samuel Arwood - You can set the delimiter to pick 6 in the first initial code - in.useDelimiter("[\\s\n]");
I think Samuel is also under the impression that the Scanner(InputStream) will do one line, and return no more tokens. The Scanner that take the inputstream will read until the end of stream is reached, and not just a single line. For what the OP wants, it may be better to just read the line from standard input manually, and then use the scanner that takes a string to process the line.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Can someone please tell me why I get stuck in this while loop?