回答編集履歴
2
追記
test
CHANGED
@@ -1 +1,67 @@
|
|
1
1
|
`[1-9][0-9]{0,4}`で充分な気がしますが...
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
利用イメージ
|
6
|
+
|
7
|
+
---
|
8
|
+
|
9
|
+
```Java
|
10
|
+
|
11
|
+
import java.io.*;
|
12
|
+
|
13
|
+
import java.util.regex.*;
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
class Main {
|
18
|
+
|
19
|
+
static int myInput(BufferedReader br, String prompt, Pattern p) throws IOException {
|
20
|
+
|
21
|
+
String ret;
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
System.out.print(prompt);
|
26
|
+
|
27
|
+
while(true) {
|
28
|
+
|
29
|
+
ret = br.readLine();
|
30
|
+
|
31
|
+
if(p.matcher(ret).matches()) {
|
32
|
+
|
33
|
+
break;
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
System.out.print(prompt);
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
return Integer.parseInt(ret);
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
public static void main(String[] args) throws IOException {
|
52
|
+
|
53
|
+
try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
|
54
|
+
|
55
|
+
System.out.println(
|
56
|
+
|
57
|
+
myInput(br, "1-99999: ", Pattern.compile("[1-9][0-9]{0,4}"))
|
58
|
+
|
59
|
+
);
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
```
|
1
修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
`[1-9][0-9]{4}`で充分な気がしますが...
|
1
|
+
`[1-9][0-9]{0,4}`で充分な気がしますが...
|