package com.homework.test;
/*
分析:
素数(质数)的判断——因子只有1和它本身的数
遍历1到其算术平方根,判断是否存在能使该数整除的数
*/
public class Prime {
public static boolean IsPrime(int num){
for (int i=2; i <= Math.sqrt(num); i++){
if (num % i == 0)
return false;
}
return true;
}
public static void main(String[] args){
int count = 0;
for(int i=101; i<=200; i++){
if (IsPrime(i)) {
System.out.print(i + " ");
count++;
}
}
System.out.println("\n101-200 之间有" + count+"个多少个素数");
}
}
原文:https://www.cnblogs.com/lcpp/p/13045283.html