First step is how would you solve the problem by hand? Write out the algorithm on a piece of paper (or in a text document, whichever) and then you're ready to begin implementing it in Java.