blob: e191835131d2a4912fd4b3ca20a73129f321ef72 (
plain)
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
|
public class Main {
public static void main(String[] args) {
System.out.println("Lets find some primes!!");
int runto = 10000;
if (args.length > 0) {
runto = Integer.parseInt(args[0]);
}
// Calculate length of runto as string
int numlen = String.valueOf(runto).length();
PrimeGen pg = new PrimeGen();
int p;
int index = 1;
while ((p = pg.next(runto)) != -1) {
// Terrible two level format
System.out.printf(String.format("%%-%dd ", numlen), p);
if (index % 10 == 0) {
System.out.print(System.lineSeparator());
}
index++;
}
System.out.print(System.lineSeparator());
System.out.printf("Found %d primes%n", index-1);
}
}
|