Loops Question In Java Leetcode Problems