C:\Users\ar114\Documents\NetBeansProjects\Exam2_CalebFontenot\src\exam2_calebfontenot\Problem3.java |
package exam2_calebfontenot;
import java.util.Scanner;
@author
public class Problem3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int currentPrime = 0, timesToIterate = 0, timesIncremented = 0;
while (timesToIterate != -1) {
System.out.print(" " + "===> -1 to quit or enter the number of primes you need generated and i will print 10 per line: ");
timesToIterate = input.nextInt();
if (timesToIterate != -1) {
for (int i = 0; i <= timesToIterate; i++) {
currentPrime++;
for (int j = 1; j < timesIncremented; j++) {
if (currentPrime % j == 0) {
System.out.print(currentPrime + " ");
}
timesIncremented++;
if (timesIncremented % 10 == 0) {
System.out.println();
}
}
}
}
}
}
}