// CSE 142, Autumn 2007, Marty Stepp // This program prints how many factors two numbers have. public class Factors { public static void main(String[] args) { System.out.println("42 has " + countFactors(42) + " factors."); System.out.println("17 has " + countFactors(17) + " factors."); } // Counts and returns how many the factors the given number has. public static int countFactors(int n) { int count = 0; for (int i = 1; i <= n; i++) { if (n % i == 0) { // i is a factor of n count++; } } return count; } }