Java Hackerrank Solution For Loop