```
public class Solution {
public int countPrimes(int n) {
boolean bool[] = new boolean[n];
int counter = 0;
int j = 0;
for (int i = 2; i <= Math.floor(Math.sqrt(n)); i++) {
j = i + i;
if (!bool[i]) {
while (j < n) {
if (!bool[j]) bool[j] = true;
j = j + i;
}
}
}
for (int i = 2; i < bool.length; i++) {
if (!bool[i]) {
counter++;
}
}
return counter;
}
```

}