隔夜茶水能浇青菜吗:如何利用JAVA求解0-100之间的素数之和?特急!

来源:百度文库 编辑:高考问答 时间:2024/04/29 20:32:37
希望高手多一些注释,谢谢!

public class Primes
{
public static void main(String[] args)
{
int total = 0;
for (long i = 2; i <= 100; i++)
{
long a = 1;
for (long n = 2; n <= Math.sqrt(i); n++)
{
a = a * ( i % n);
if ( i % n >= 2)
{
a = a / 2;
}
}
if (a != 0)
{
total += i;
}
}
System.out.println(total);
}
}