Last active
August 29, 2015 14:12
-
-
Save RussellAndrewEdson/973a4c8236beb7499b7a to your computer and use it in GitHub Desktop.
Common interface for our primality tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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