Skip to content

Commit b8ad277

Browse files
committed
improve SSOZJ5Runner
1 parent f42079f commit b8ad277

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed
Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project.
3-
* Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de
3+
* Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de
44
*
55
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
66
* as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
@@ -13,8 +13,11 @@
1313
*/
1414
package de.tilman_neumann.jml.primes.exact;
1515

16+
import java.io.BufferedReader;
17+
import java.io.InputStreamReader;
1618
import java.math.BigInteger;
17-
import java.util.Scanner;
19+
20+
import static de.tilman_neumann.jml.base.BigIntConstants.I_0;
1821

1922
public class SSOZJ5Runner {
2023

@@ -23,18 +26,31 @@ public class SSOZJ5Runner {
2326
* @param args ignored
2427
*/
2528
public static void main(String[] args) {
26-
Scanner userInput = new Scanner(System.in).useDelimiter("[,\\s+]");
27-
System.out.println("Please enter a space-separated range of integers: ");
28-
BigInteger stop = userInput.nextBigDecimal().toBigIntegerExact();
29-
BigInteger start = userInput.nextBigDecimal().toBigIntegerExact();
30-
userInput.close();
29+
while (true) {
30+
try {
31+
System.out.println("\nPlease enter the range in integer(s) [<start>] <stop>:");
32+
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
33+
String line = in.readLine();
34+
String[] splitted = line.split("\\s+");
35+
int argc = splitted!=null ? splitted.length : 0;
36+
BigInteger start, stop;
37+
if (argc == 0 || argc > 2) {
38+
System.err.println("Illegal input.");
39+
continue;
40+
}
41+
if (argc == 1) {
42+
start = I_0;
43+
stop = new BigInteger(splitted[0]);
44+
} else {
45+
start = new BigInteger(splitted[0]);
46+
stop = new BigInteger(splitted[1]);
47+
}
3148

32-
if (stop.compareTo(start) < 0) {
33-
BigInteger tmp = start;
34-
start = stop;
35-
stop = tmp;
49+
SSOZJ5.twinprimes_ssoz(start, stop);
50+
51+
} catch (Exception e) {
52+
System.err.println("Error " + e);
53+
}
3654
}
37-
38-
SSOZJ5.twinprimes_ssoz(start, stop);
3955
}
4056
}

0 commit comments

Comments
 (0)