Post edited to include [code][/code] bbcode tags, as you can see they make code sample
much easier to read by retaining formatting
OK, now I preface this by stating I do not know java, and can not even test your code.
I guess maybe it's waiting for input before displaying it's message "Enter a word and a letter", since the input.next() commands come before the user is prompted for input. I found this tutorial that does it prompt first then input.next(), from a local uni:
http://www.csc.liv.ac.uk/~frans/OldL...ek3/input.html
Looks like the infinite loop is perhaps caused by mixing up inputString and theCharacter in the while loop's if statement - I guess:
Code:
if (theCharacter.charAt(i)== theChar)
should be
Code:
if (inputString.charAt(i)== theChar)
But I also guess that after one match on first pass through the loop, the theCharacter.charAt(i) should resolve to theCharacter.charAt(1) - which should be null. so it'll execute the else block - in which count is set to zero (why? this will happen on every letter not matching theChar, no matter if matches have been detected in prioor parts of the input word - not I think what is intended) - and i and j, the conditionals for exiting the loop are not incremented / decremented. So once your code path fails the if(test), and execution gets in to this else block - it's never coming out, since it will just repeat the same test over and over never advancing along the input word.
At least I hope that made sense!
Last edited by _dave_; 04-24-2012 at 06:48 PM.
Reason: omg I took a while to "learn Java" (read my link) and type this post, ninja'd by 20+ minutes!