Basic Algorithms in Java Assignment