这里只是以求三位循环素数为例子。
public class CirclePrimeNumber
{
public static boolean isPrime(int n)
{
for (int i = 2; i <= Math.sqrt(n); i++)
{
if (n % i == 0)
{
return false;
}
}
return true;
}
public static int circle(int n)
{
int a = n % 10;
int b = n / 10;
return a * 100 + b;
}
public static void main(String[] args)
{
int count = 0;
int temp = 0;
for (int i = 999; i >= 100; i--)
{
count = 0;
temp = i;
for (int j = 1; j <= 3; j++)
{
if (isPrime(temp))
{
count++;
temp = circle(i);
}
else
{
break;
}
}
if (count == 3)
{
System.out.println(i);
}
}
}
}
可以参考点击打开链接