forked from goldshtn/linux-tracing-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlowy.java
33 lines (27 loc) · 841 Bytes
/
Slowy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package slowy;
class App {
private static boolean isDivisible(int n, int d) {
return n % d == 0;
}
private static boolean isSimplePrime(int n) {
return n <= 2;
}
private static boolean isPrime(int n) {
if (isSimplePrime(n)) return true;
for (int d = 3; d < n; d += 2) {
if (isDivisible(n, d)) return false;
}
return true;
}
public static void main(String[] args) throws java.io.IOException {
System.out.println("Press ENTER to start.");
System.in.read();
int count = 0;
for (int n = 2; n < 200000; ++n) {
if (isPrime(n)) ++count;
}
System.out.println(String.format("Primes found: %d", count));
System.out.println("Press ENTER to exit.");
System.in.read();
}
}