标签:str pack lag new string break 素数 for system
若两个素数之差为2,则称其为孪生素数
package 孪生素数; public class 孪生素数 { public static void main(String[] args) { int i,j; int flag, n = 0; int a[] = new int[100]; for(i = 2; i <= 100; i++) { flag = 1; for(j = 2; j < i; j++) { if(i%j == 0) { flag = 0; break; } } if(flag == 1) { a[n] = i; n++; } } System.out.println("100以内的孪生素数如下:"); for(i = 0; i < n-1; i++) { if(a[i+1]-a[i] == 2) { System.out.print(a[i]+" "); System.out.print(a[i+1]+" "); System.out.println("\n"); } } } }
标签:str pack lag new string break 素数 for system
原文地址:https://www.cnblogs.com/JAYPARK/p/10289564.html