Since you have posted this in 12 other forums, and have received an answer in C in one of them, I will help everybody out by letting them know not to bother. You have your actual code in C, now YOU should translate that into Java.