public class Prime {
public static void main(String[] args) {
int i,count=0;
for(i=101;i<=200;i++)
{
if(isPrime(i))
{
System.out.print(i+",");
count++;
}
if(count%10==0)
System.out.println("");
}
System.out.println("\n"+count);
}
private static boolean isPrime(int n) {
int k = (int)Math.sqrt(n);
int i;
for(i=2; i<=k; i++){
if(n % i == 0){
break;
}
}
if(i > k){
return true;
}
return false;
}
} |