Java Algorithm practice.