//on jetbrains IDE
To examine how the program operates at runtime, we need to suspend its
execution before the suspected piece of code. This is done by setting
breakpoints. Breakpoints indicate the lines of code where the program
will be suspended for you to examine its state.
public class PerfectSquareCounter {
static int evenPerfectSquareNumbers = 0;
public static void main(String[] args) {
int i = 100;
System.out.println("Total Perfect Squares: " + calculateCount(i));
System.out.println("Even Perfect Squares : " + evenPerfectSquareNumbers);
}
public static int calculateCount(int i) {
int perfectSquaresCount = 0;
for (int number = 1; number <= i; number++) {
if (isPerfectSquare(number)) {
perfectSquaresCount++;
if (number % 2 == 0) {
evenPerfectSquareNumbers++;
}
}
}
return perfectSquaresCount;
}
private static boolean isPerfectSquare(int number) {
double sqrt = Math.sqrt(number);
return sqrt - Math.floor(sqrt) == 0;
}
}
Copy