java编程求1-50内素数之和
public static void main(String[] args) {
int sss = 0;
for(int n=2;n<=100;n++) {
int i = n;
boolean f = true;
int t = 0;
for (int j = 2; j <= i - 1; j++) {
if (i % j == 0) {
t = j;
f = false;
break;
}
}
if (f) {
System.out.printf("% 3d ",i);
sss+=i;
}
}
System.out.println();
System.out.printf("1-100内素数和是:%d%n",sss);
}
运行结果如下