Some algorithms in Java