This week's giveaway is in the Cloud/Virtualization forum. We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line! See this thread for details.
Hi Wayne and Campbell, I'm new in CodeRanch, I would like to add my two cents to the problem
but of course Wayne do as your Instructor at Bootcamp tells you, this is just my opinion to the problem and a possible answer.
The best answer anyway is always using Regular Expressions as Campbell mentioned it before.
posted 2 months ago
Welcome to the Ranch
Thank you for the suggestion, but I can see things I would change about it.
Don't close your Scanner reading System.in; it isn't necessary and can cause problems if you want to read again.
I don't like break; and there is a way you can use your boolean to avoid break; Otherwise you could dispense with that variable.
All local variables must be initialised before they can be used; they don't have defulat values like fields. I can see a potential bug with the iterations counter.
We don't know that there are always two digits before the letters, so the bit about index 2 or 3 might not work correctly.
Only use \n if somebody has said they want the LF character. Otherwise use printf and %n. That will give you the correct line end for your OS.
Hi Campbell, you are right with Scanner, \n could be completely avoided as you mention, I just left it as the original code but you are right in your comments
I used break in order to don't iterate over long words let's say a String with hundred of characters, break allow me to just go away from the loop at once, and iterators tells me always how many iterations has been made.
Regarding the characters at zero and one index, if not digits they will go in the else statement and then with a break it won't count it.
There are many ways to approach this code problem as you mention.
Thank you again for your comments and advices Campbell.
It's good to be here at JavaRanch, thanks again guys.
Seriously Rick? Seriously? You might as well just read this tiny ad:
global solutions you can do in your home or backyard