Skip to content

Instantly share code, notes, and snippets.

@RussellAndrewEdson
Last active August 29, 2015 14:12
Show Gist options
  • Save RussellAndrewEdson/973a4c8236beb7499b7a to your computer and use it in GitHub Desktop.
Save RussellAndrewEdson/973a4c8236beb7499b7a to your computer and use it in GitHub Desktop.
Common interface for our primality tests.
import java.math.BigInteger;
/** A common interface for the primality tests we'll look at. */
public abstract class PrimalityTest {
public abstract boolean isPrime(BigInteger n);
public void timedPrimeTest(BigInteger n) {
System.out.println("Running test: " + getClass().getName());
System.out.println("n: " + n);
long startTime = System.currentTimeMillis();
System.out.println("Prime?: " + isPrime(n));
long elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("Time taken: " + elapsedTime + " milliseconds.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment