View difference between Paste ID: 0MLLTYym and r7gdBGq9
SHOW: | | - or go back to the newest paste.
1
import java.util.ArrayList;
2
public class Prime_Counter {
3
	static ArrayList<Integer> primes = new ArrayList<Integer>();
4-
	static int prime, target = 2, basePrime = 1, largestFactor, nextTest = 1;
4+
	static int target = 10001;
5
	
6
	public static void main(String[] args) {
7-
		System.out.println("" + prime(basePrime) + " is the " + target + " prime.");	
7+
8
		
9
		while (primes.size() != target){
10-
	public static int prime(int x)
10+
			next();
11-
	{
11+
		}// end of primes while
12-
		System.out.println("Target is: " + target);
12+
13-
		System.out.println("The size of the primes array is: " + primes.size());
13+
		System.out.println("" + primes.get(primes.size()-1) + " is the " + target + " prime.");
14-
		System.out.println("Is " + x + " prime?");
14+
15-
		largestFactor = findLargestFactor(x);
15+
16
	public static void next(){
17-
		for (int y = 2; y <= Math.pow(largestFactor, 0.5); y++){
17+
		int largestPrime = primes.get(primes.size()-1);
18-
			if(x%y == 0)
18+
		int z = largestPrime;
19
		boolean found = false;
20-
				System.out.println("" + x + " is not prime.");
20+
21-
				nextTest = nextNumber();
21+
		while (!found){
22-
				System.out.println("Next test is: " + nextTest);
22+
			z++;
23-
				return prime(nextTest);
23+
			if (prime(z))
24-
			}// end of if
24+
25-
		}// end of y for loop
25+
				found = true;
26
				System.out.println("" + z +" is prime.");
27-
		System.out.println("" + x + " is prime.");
27+
				primes.add(z);
28-
		primes.add(x);
28+
			}
29-
29+
		}// end of y while loop
30-
		System.out.println("Target is: " + target);
30+
	}// end of next
31-
		System.out.println("The size of the primes array is   : " + primes.size());
31+
32
	public static boolean prime(int x){
33-
		if(primes.size() == target)
33+
		System.out.println("Is " + x +" prime?");
34-
			return primes.get(target-1);
34+
		for (int y = 2; y <= Math.pow(x, 0.5); y++){
35
			if (x%y == 0)
36-
		nextTest = nextNumber();
36+
37-
			
37+
				System.out.println("" + x +" is not prime.");
38-
			return prime(nextTest);
38+
				return false;
39
			}
40-
40+
		}// end of for y loop
41-
	public static int findLargestFactor(int x)
41+
		return true;
42-
	{
42+
43-
		for (int y = 2; y <= Math.pow(x, 0.5); y++)
43+