㈠ java实现1000以内回文素数(质数)
publicclass${
publicstaticvoidmain(String[]args){
for(inti=1;i<=1000;i++){
if(!check(i)){
continue;
}
if(huiweishu(i)){
System.out.println(i);
}
}
}
privatestaticbooleancheck(intnum){
intsqrt=(int)Math.sqrt(num);
for(intj=2;j<sqrt+1;j++){
if(num%j==0){
returnfalse;
}
}
returntrue;
}
privatestaticbooleanhuiweishu(inti){
inta;
if(i<99){
a=i/10;
}else{
a=i/100;
}
returna==i%10;
}
}
11
101
131
151
181
191
313
353
373
383
727
757
787
797
919
929
㈡ 鍙岖礌鏁帮纸阃嗗悜𨰾煎啓镄勭礌鏁帮级缂栧啓java绋嫔簭
public class TempCls
{
public static boolean isPrime(long n)
{ //鍒ゆ柇绱犳暟
int i = 2;
while (i*i <= n)
{
if (n % i ==0)
return false;
i++;
}
return true;
}
public static String reverseStr(String str)
{ //鍙嶈浆瀛楃︿覆
String result = "";
for (int i = str.length()-1; i >= 0; i--)
{
result += str.charAt(i);
}
return result;
}
public static boolean reverseJudge(long n)
{ //鍙嶈浆鏁板瓧鍒ゆ柇
String nStr = reverseStr(n + "");
return isPrime(Integer.parseInt(nStr));
}
public static boolean isPalindromic(long n)
{ //锲炴枃鍒ゆ柇
String str1 = n + "";
String str2 = reverseStr(str1);
return !str1.equals(str2);
}
public static void main(String[] args)
{
int n = 0; //璁℃暟鍣
int i = 2; //1涓嶆槸绱犳暟锛屾晠浠2寮濮
while (n < 100)
{
if (isPalindromic(i) && isPrime(i) && reverseJudge(i))
{
System.out.print(i + "\t\t");
n++;
if (n % 10 == 0)
System.out.println();
}
i++;
}
}
}
㈢ 锲炴枃绱犳暟鏄浠涔
浠庡乏钖戝彸璇讳笌浠庡彸钖戝乏璇绘槸瀹屽叏涓镙风殑锛岃繖镙风殑鏁扮О涓衡滃洖鏂囨暟钬濄傚洖鏂囨暟涓瀛桦湪镞犵┓澶氢釜绱犳暟11锛101锛131锛151锛191钬︹︺傞櫎浜11浠ュ栵纴镓链夊洖鏂囩礌鏁扮殑浣嶆暟閮芥槸濂囨暟銆傞亾鐞嗗緢绠鍗曪细濡傛灉涓涓锲炴枃绱犳暟镄勪綅鏁版槸锅舵暟锛屽垯瀹幂殑濂囨暟浣崭笂镄勬暟瀛楀拰涓庡伓鏁颁綅涓婄殑鏁板瓧鍜屽繀铹剁浉绛夛绂镙规嵁鏁扮殑鏁撮櫎镐х悊璁猴纴瀹规槗鍒ゆ柇杩欐牱镄勬暟镶瀹氲兘琚11鏁撮櫎锛屾墍浠ュ畠灏变笉鍙鑳芥槸绱犳暟銆
链杩戝彂鐜扮殑链澶х殑鍗佷釜锲炴枃绱犳暟:
742950290870000078092059247, 742950290871010178092059247,742950290872020278092059247, 742950290873030378092059247,742950290874040478092059247, 742950290875050578092059247,742950290876060678092059247, 742950290877070778092059247,742950290878080878092059247, 742950290879090978092059247