Think how you'd do this with pencil & paper ...
Break the sentence into words and count them.
Pick a chunk size, say 5.
Figure out how many chunks you're going to have. The last chunk might be short but you still have to count it.
Take the first n words and copy them to chunk 1.
Take the next n words and copy them to chunk 2.
repeat until done ...
With pencil & paper you don't remove words from the list, you just move your finger along the list to point at the next word to copy. An array index does the very same thing. You know you're done when your finger goes past the end of the list. How do you check for an array index going past the end?
With pencil & paper you probably don't care how many chunks you're going to make. You just start a new line for each one. Have you thought about where you're going to put your chunks? If you put them into an array (the two dimensional array idea from above) you'll have to know the count to make the array. If you put them into a List or Set you won't have to know ahead of time and you can skip that step.
BTW: To count the words in the list use split to get an array and see how long the array is.
Give it a shot in
Java. Post what you come up with!
[ April 16, 2006: Message edited by: Stan James ]