// CSE 142, Summer 2008 (Marty Stepp) // This "module" contains shared code related to factoring. // It is not a complete program, but its methods can be called by other programs. public class Factors { // Returns the number of factors of the given integer. public static int countFactors(int number) { int count = 0; for (int i = 1; i <= number; i++) { if (number % i == 0) { count++; // i is a factor of the number } } return count; } // Returns true if the given number is prime. public static boolean isPrime(int number) { return countFactors(number) == 2; } }