Calculating the perfect squares between two given numbers
First things first. You have to organize your code and group functionality into methods. So I would suggest creating a method int[] getPerfectSquaresBetween(int start, int end).

Let's enhance your algorithm. The key idea is to get the square root of the next perfect square number. This can be achieved by ceil the sqrt of the starting point:

int candidate = (int) Math.ceil(Math.sqrt(start));


This variable is the basis for our calculations. All we have to do now is to check if the candidate squared is in the given range.

int square;
while ((square = candidate * candidate) &lt; end) {
  //...
  candidate++;
}


Putting everything together looks like this:

public static int[] getPerfectSquaresBetween(int start, int end) {
  if (start &gt; end || start &lt; 0) {
    throw new IllegalArgumentException();
  }
  int[] perfectSquares = new int[end - start];
  int nr = 0;
  int candidate = (int) Math.ceil(Math.sqrt(start));
  int square;
  while ((square = candidate * candidate) &lt; end) {
    perfectSquares[nr++] = square;
    candidate++;
  }
  return Arrays.copyOf(perfectSquares, nr);
}


Let's check the algorithm: getPerfectSquaresBetween(0, 101) (which completes in microseconds)


  [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]