You want your end loop condition to be what you're using to see if it's right. So the loop ends when the input is right.

It's never too soon to talk about design and/or refactoring. I generally like to break methods up into fairly atomic units of work. Again, once you have a decent algorithm, the code practically writes itself. Here's an example:

Pseudocode:
1) Ask the user for a word
2) Ask the user for another word
3) Display the words

That's the basic idea of the program. We'll see that each step has its own set of requirements, but let's just start with this algorithm of program flow.

Okay, this obviously won't compile (the methods aren't defined), but I'm not too worried about it. This pretty much covers the main program, right? Now, we just need to define those methods. We'll write some basic methods as "stubs", just to get a working program...

Hopefully you're getting the idea here. Solve your problems by tackling one small thing at a time. Think of the algorithm first, then write code in a stepwise fashion. Test each little bit as you go. Hopefully this simple example will start you well on your way toward completing your program.

Good luck!

Comments on this post

Guelphdad agrees
: In depth answers like this are why I love Dev Shed! Wonderful.

Ok I have tidied it up abit I think But I still cant seem to get it to loop back to the inputs if there is an error in the length of the word. I really appreciate the help so far aswell, it has giving me a much better understanding of programming.

Everything is still piled into the main method, and begs to be refactored. Each method should do one thing, and do it well. Don't make your main method work so hard...

But I still cant seem to get it to loop back to the inputs if there is an error in the length of the word.

Either you haven't yet developed an understanding of what the algorithm for such an action should be, or you don't understand how to translate that algorithm to Java. Either way, you haven't written your program to "loop back to the inputs"; you must tell the computer what you want it to do, and there's nothing in your example that says "keep trying to get input if it isn't correct". Please study the code I posted, especially the getWordFromUser() method.

Sorted it, I was using if's instead of whiles and I have broken it down some. Thanks alot for the input guys, I like how you didnt just drop an answer to my question without trying to make me understand what it was I was trying to achieve. I will no doubt have many more questions as I try and gain a wider understanding of Java.

Thanks again.

Stephen

Comments on this post

crownjewel82 agrees
: Thanks for not being lazy and wanting help not handouts.

Yawmark agrees
: Glad you're working on it. Your success is due, no doubt, to your regal first name... :)