Basic/Practice algorithms, problem solutions in Java