First off, welcome to JavaRanch!
Secondly, we have a couple policies that we follow. One is
DoYourOwnHomework. This sounds supsiciously like a homework question. A couple more policies are
ShowSomeEffort and
NotACodeMill. We are more than happy to help, we just won't do the work for you.
Here are my recommendations:
1. Break down your problem into small parts, and work out by hand in plain English how to accomplish this task.
2. Read the Java Tutorial on Sun's site, and do some googling to find out the basics of reading from the command line, looping, and printing in Java.
SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."