Java: R&A algorithm is finished!