private static void prime(int i){ int j = 2; while(true){ while(i%j == 0 && i != j){ System.out.println("Prime num " + j); i = i/j; } if(i == j){ System.out.println("Prime num " + j); break; } j++; } }
private static void prime1(int i){ for(int j = 2; j < i; j++){ while(isPrime(j) && i%j==0){ System.out.println("prime num " + j); if(i != j){ i = i/j ; } else { System.out.println("prime num " + i); break; } } } } static boolean isPrime(int number) { for (int i = 2; i*i < number; i++) { if (number % i == 0 && i != number) return false; } return true; }
原文地址:http://my.oschina.net/u/138995/blog/293276