/** * This file contains java code which implements * the class named CommentsBad. */ public class CommentsBad { public void displayPrimes(int maxNumber) { int[] array; // An array of integers // Declare array array = new int[maxNumber + 1]; // Initialize array for (int i=2; i<=maxNumber; i++) { array[i] = i; } // Perform a nested loop over array with the outer loop going // from 2 to Sqrt(maxNumber) and the inner loop going from // 2 time the value of the outer loop to maxNumber. for (int i=2; i<=(int)Math.sqrt(maxNumber); i++) { for (int j=2*i; j <= maxNumber; j+=i) { array[j] = 0; // Set to 0 } } // Loop over array and for every value that is not equal to 0, // call the method System.out.println(). for (int i=2; i<=maxNumber; i++) { if (array[i] != 0) { System.out.println(array[i]); } } } /** * A simple class tester * @param args Unused */ static public void main(String[] args) { CommentsBad bad = new CommentsBad(); bad.displayPrimes(20); // Simple test case } }