求素数是的约数用'%'求余运算符
用循环表示
让j++;
如果temp%j == 0;
表示temp有约数,约数为j
多看看书,一般书上都会有的.
你的另一个主题我也帮你看了,那个要复杂一点
public class example2 {
public static void main(String[] args) {
final int MAX = 100;
int temp = 1;
int count = 1;
System.out.println("100以内的质数是:");
while(temp <= MAX)
{
int j =2;
while(j <= Math.sqrt(temp) )
{
if(temp%j == 0)
break;
j++;
}
if(j >Math.sqrt(temp))
{
System.out.print(temp+"\t");
count ++;
}
if(count%10 == 0)
{
System.out.println();
count = 1;
}
if(temp < 3)
temp ++;
else temp += 2;
}
}
}