```
public class Solution {
public int countPrimes(int n) {
int count = 0;
if (n<=2) return 0;
boolean[] boo = new boolean[n];
int i=0;
for (; i<n;i++) {
boo[i] = true;
}
for ( i=2; i<n; i++) {
if (boo[i]) {
count++;
for (int j=2*i; j<n; j+=i) {
boo[j]=false;
}
}
}
return count;
}
}
```