Skip to content

Instantly share code, notes, and snippets.

@jankotek
Created April 2, 2016 18:59
Show Gist options
  • Save jankotek/8fcb8205dbe1b8d131cdac2cc2342f36 to your computer and use it in GitHub Desktop.
Save jankotek/8fcb8205dbe1b8d131cdac2cc2342f36 to your computer and use it in GitHub Desktop.
package org.mapdb.crash;
/**
* Created by jan on 4/2/16.
*/
public class Prime {
static boolean isPrime(int n) {
boolean prime = true;
for(int a=2; a<n; a = a+1) {
if(n % a == 0) {
prime = false;
}
}
return prime;
}
public static void main(String[] args) {
while(true){
long begin = System.currentTimeMillis();
int numberOfPrimes = 0;
int max = 100000;
for(int b=2; b<max; b = b+1) {
if (isPrime(b) == true) {
numberOfPrimes++;
}
}
long end = System.currentTimeMillis();
double elapsed = ((double)(end - begin)) / 1000;
System.out.println("" + numberOfPrimes + " primes between 0 and " + max);
System.out.println("Time taken = " + elapsed );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment