package test01;
public class ARRARY {
public static void main(String[] args)
{
int[] result = new int[50];//暂定存50个位置
int count = 0;//用于记录数组位置
// boolean a = true;
for (int i = 2; i < 1001; i++)//将所有数开始循环去除以比他小的数,如有能除尽的(大于1及小于本身),则不是质数,反之是质数
{
boolean a = true; //用来记录每次是质数的时候
for (int j = 2; j < i; j++)
{
if (i % j == 0)
{
a = false;//不变即是质数
break;
}
}
if (a)
{
result[count] = i;//将质数i放入数组位置count
count++;//如果位置被用过了,则将位置加1
if (count >= result.length)//如果需要放的数量大于了数组总长度,则退出
{
break;
}
}
}
for (int i : result) //迭代循环输出数组
{
System.out.println(i);
}
}
}