Skip to content

Instantly share code, notes, and snippets.

@chaixdev
Last active October 22, 2017 22:59
Show Gist options
  • Save chaixdev/c0aeabd7d27aa3e479e840b3852a388d to your computer and use it in GitHub Desktop.
Save chaixdev/c0aeabd7d27aa3e479e840b3852a388d to your computer and use it in GitHub Desktop.
package util;
import Printer.Printer;
public class PrimeFinder {
private Printer printer;
public PrimeFinder(Printer p){
this.printer = p;
}
boolean isPrime(int n) {
for(int i=2;2*i<n;i++) {
if(n%i==0)
return false;
}
return true;
}
public void printValidPrimeTuples(int rangeMax) {
for(int a=0;a<rangeMax;a++) {
if(isPrime(a)) {
for(int i=0;i<3;i++) {
if(isPrime(a+i)); printer.print(String.format("(%d,%d)",a,a+i));
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment