Help... Any Idea on how to solve this

Hi everybody,
my teacher left us a homework about a topic that we havent seen, he didnt even tell us the topic so we could research…, well, the problem is this one:

http://www.karrels.org/Ed/ACM/reg94/prob_f.html

there is a sollution written in C, we need to submit one made in Java, so, i was wondering if anyone of you programming gurus could help me… and point me in the right direction on how to solve it.

tnx in advance.:snug: