54 lines
1.9 KiB
Java
54 lines
1.9 KiB
Java
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package exam2_calebfontenot;
|
|
|
|
import java.util.Scanner;
|
|
|
|
/**
|
|
*
|
|
* @author ar114
|
|
*/
|
|
public class Problem3 {
|
|
|
|
public static void main(String[] args) {
|
|
// Create scanner
|
|
Scanner input = new Scanner(System.in);
|
|
|
|
// Define args
|
|
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: ");
|
|
|
|
// Get amount of times the user wants us to iterate for.
|
|
timesToIterate = input.nextInt();
|
|
|
|
// Don't do anything if the input is -1
|
|
if (timesToIterate != -1) {
|
|
// First loop. This determines how many times to iterate.
|
|
for (int i = 0; i <= timesToIterate; i++) {
|
|
currentPrime++;
|
|
|
|
// It's broken somewhere here, but I'm not sure where exactly...
|
|
// Generate primes by incrementing currentPrime and attempting to divide by itself.
|
|
for (int j = 1; j < timesIncremented; j++) {
|
|
if (currentPrime % j == 0) {
|
|
System.out.print(currentPrime + " ");
|
|
}
|
|
timesIncremented++;
|
|
// If we've incremented 10 times, print a new line.
|
|
if (timesIncremented % 10 == 0) {
|
|
System.out.println();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|