//求1000以内的所有质数(只能被1和本身整除)
public class Homework1
{
public static void main(String[] args)
{
System.out.println("1000以内的质数有:");
int count=1;
for(int m=2;m<1000;m++)
{
if(2==m || 3==m)
{
System.out.print(m+" ");
count++;
}
else
{
int j=2;
while(j<m)
{
if(m%j==0)
{
break;
}
j++;
}
if(j==m)
{
System.out.print(m+" ");
count++;
}
}
if(count%10==0)
{
System.out.println();
}
}
System.out.println("1000以内的质数共有:"+count+" 个");
}
}
public class Homework1
{
public static void main(String[] args)
{
System.out.println("1000以内的质数有:");
int count=1;
for(int m=2;m<1000;m++)
{
if(2==m || 3==m)
{
System.out.print(m+" ");
count++;
}
else
{
int j=2;
while(j<m)
{
if(m%j==0)
{
break;
}
j++;
}
if(j==m)
{
System.out.print(m+" ");
count++;
}
}
if(count%10==0)
{
System.out.println();
}
}
System.out.println("1000以内的质数共有:"+count+" 个");
}
}