// Write a program that prints the first n positive integers that // are evenly divisible by at least 5 positive integers. // // Example: n = 10 // Desired output: 12 16 18 20 24 28 30 32 36 40 public class DivisibleBy5 { public static void main(String[] args) { int printed=0, current=1, numDivisors=0, currDivisor; int numWanted; // read in the number of integers wanted TokenReader in = new TokenReader(System.in); System.out.println("How many integers do you want?"); numWanted = in.readInt(); // leave a blank line and print the start of the output System.out.println(); System.out.println("The first " + numWanted + " positive integers divisible by 5 positive integers are:"); // iterate until n integers are printed out while (printed < numWanted) { // find out how many positive integers the current // number is divisible by currDivisor = 1; // need currDivisor == 0 to start while (currDivisor <= current) { if (current % currDivisor == 0) ++numDivisors; ++currDivisor; } // print the current number if enough divisors were found if (numDivisors >= 5) { ++printed; System.out.print(current + " "); } // setup to check the next number numDivisors=0; ++current; } } }