标签:
1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 for(int i = 3; i <= 1000; i++) 6 if(isDoublePrime(i)) 7 System.out.println("(" + i + ", " + (i + 2) + ")"); 8 } 9 10 public static boolean isDoublePrime(int n) 11 { 12 if(isPrime(n) && isPrime(n + 2)) 13 return true; 14 else 15 return false; 16 } 17 18 public static boolean isPrime(int n) 19 { 20 if(n == 1) 21 return false; 22 else if(n == 2) 23 return true; 24 else 25 { 26 for(int i = 2; i < n; i++) 27 { 28 if(n % i == 0) 29 return false; 30 } 31 return true; 32 } 33 } 34 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5797102.html