{:soso_e127:}
public class he {
public static void main(String[] args) {
int i = 2;
int j = 2;
int sum = 0;//质数和
while (i <= 100) {
j=2;
boolean zhiShu=true;
while (j < i) {
if (i % j == 0){//i是否能被2到i之间的数整除
zHISHU=false;//不是质数
break;
}
j++;
}
if(zHISHU){
sum+=i;
}
i++;
}
System.out.println("1-100之间质数的和为:"+sum);
}
}
public static boolean isPrimeNumber(int number) {
if (number < 2) {
return false;
}
for (int i = 2; i <= Math.sqrt(number); i++) {
if (number % i == 0 && number != 2) {
return false;
}
}
return true;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int sum = 0;
for (int i = 2; i <= 100; i++) {
if (isPrimeNumber(i))// 如果是质数,则累加它
{
sum += i;
}
}
System.out.println(sum);
}