// CSE 142, Autumn 2009, Marty Stepp // This "module" class is not a complete program. // It just contains global static code to be used by other client programs. public class FactorsModule { // static 'global' variables (usually bad, unless final) public static final int FIRST_PRIME = 2; // 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; } }