Backup of code I wrote to calculate patterns between prime numbers.

read more

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;


public class determineWhatNumbersYouCantAddToPrime {

/**
* @param args
*/
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
File file = new File("/Users/Puccio/Desktop/PRIMES1T.TXT");
Scanner primesArray = new Scanner(file);
ArrayList primes = new ArrayList();
ArrayList allPrimes = new ArrayList();
for (int i = 0; i < 1000; i++) {
allPrimes.add(primesArray.nextInt());
}

for (int i = 1; i < 10; i++) {
ArrayList numbersYouCantAdd = new ArrayList();
int currentPrime = i; //You can change this to (Integer) allPrimes.get(i); if you want to start from primes
System.out.print(currentPrime + " You can add ");
for (int a = 2; a < currentPrime; a++) {
	int cantAdd= a - (currentPrime % a);
	numbersYouCantAdd.add(cantAdd);
	
	for(int g=1;(a*g)+cantAdd<currentPrime;g++){
		numbersYouCantAdd.add(((a*g)+cantAdd));
	}
	
	
}

HashSet hs = new HashSet();
hs.addAll(numbersYouCantAdd);
numbersYouCantAdd.clear();
numbersYouCantAdd.addAll(hs);
/**
for (int p = 0; p < numbersYouCantAdd.size(); p++) {
	System.out.print(numbersYouCantAdd.get(p));
	if (p != numbersYouCantAdd.size() - 1) {
		System.out.print(" or ");
	}

}
 */
ArrayList whatYouCanAdd = new ArrayList();
for(int y = 1; y<currentPrime;y++){
	if(!numbersYouCantAdd.contains(y)){
		whatYouCanAdd.add(y);	
	}	
	}
for(int d=0;d<whatYouCanAdd.size();d++){
	System.out.print(whatYouCanAdd.get(d));
	if (d != whatYouCanAdd.size() - 1) {
		System.out.print(" or ");
	}
}
			
for(int j=0;j<whatYouCanAdd.size();j++){
	primes.add(currentPrime+(Integer)whatYouCanAdd.get(j));
}



System.out.println();

}
HashSet hs = new HashSet();
hs.addAll(primes);
primes.clear();
primes.addAll(hs);
Collections.sort(primes);
System.out.println(primes);

}

}