一道简单的JAVA题目。

来源:百度知道 编辑:UC知道 时间:2024/05/20 12:11:25
列出1到1000以内的的,对59求余后为1的质数。
要求要用多线程解决。

public class Prime {

/**
* 列出1到1000以内的的,对59求余后为1的质数。
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Prime().new thread().start();
}

class thread extends Thread
{
public void run() {
// TODO Auto-generated method stub
int a=0;
for(int i=0;i<1000;i+=59)//对59求余为1,该数肯定是59的倍数加上1后的数,
{
if(isZhiShu(i+1))//判断是否为质数。
{
a=1;
System.out.println(i+1) ;
}
}
if(a==0)
{
System.out.println("1-1000这个范围里没有这样的数") ;
}
}

}

public static boolean isZhiShu(int x)//判断是否为质数
{
for(int i=2;i<x/2;i++)
{
if(x%i==0)
{
return false;
}
}
return true;
}
}

public class PrimeNumber {
/**
* @param args
*/
public static void main(Stri