1
1
/*
2
2
* 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
4
4
*
5
5
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
6
6
* as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
13
13
*/
14
14
package de .tilman_neumann .jml .primes .exact ;
15
15
16
+ import java .io .BufferedReader ;
17
+ import java .io .InputStreamReader ;
16
18
import java .math .BigInteger ;
17
- import java .util .Scanner ;
19
+
20
+ import static de .tilman_neumann .jml .base .BigIntConstants .I_0 ;
18
21
19
22
public class SSOZJ5Runner {
20
23
@@ -23,18 +26,31 @@ public class SSOZJ5Runner {
23
26
* @param args ignored
24
27
*/
25
28
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 ("\n Please 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
+ }
31
48
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
+ }
36
54
}
37
-
38
- SSOZJ5 .twinprimes_ssoz (start , stop );
39
55
}
40
56
}
0 commit comments