2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-26 06:48:04 +02:00
LaTeX-examples/documents/Programmierparadigmen/scripts/java/SingleCorePrimeTest.java

27 lines
627 B
Java
Raw Normal View History

2014-03-24 23:25:10 +01:00
/* @author Axel Busch */
public class SingleCorePrimeTest {
public static boolean isPrime(int n) {
if (n < 2) {
return false;
}
for (int i = 2; i <= Math.sqrt(n); ++i) {
if (n % i == 0) {
return false;
}
}
return true;
}
public static void main(String[] args) {
int target = 10_000_000;
long start = System.currentTimeMillis();
for (int i = 2; i <= target; ++i) {
isPrime(i);
}
long end = System.currentTimeMillis();
System.out.println(end-start);
}
}