回答編集履歴
1
追記
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
while (true) {
|
28
28
|
|
29
|
-
int index = input_index(sc, "Index --> ", nums.length);
|
29
|
+
int index = input_index(sc, "Index --> ", nums.length - 1);
|
30
30
|
|
31
31
|
if (index == -1) {
|
32
32
|
|
@@ -95,3 +95,35 @@
|
|
95
95
|
}
|
96
96
|
|
97
97
|
```
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
追記:
|
102
|
+
|
103
|
+
try catch で書いてみました。
|
104
|
+
|
105
|
+
```java
|
106
|
+
|
107
|
+
static private int input_int(Scanner sc, String message) {
|
108
|
+
|
109
|
+
while (true) {
|
110
|
+
|
111
|
+
System.out.print(message);
|
112
|
+
|
113
|
+
try {
|
114
|
+
|
115
|
+
return sc.nextInt();
|
116
|
+
|
117
|
+
} catch (Exception ex) {
|
118
|
+
|
119
|
+
System.out.println("Input Mismatch");
|
120
|
+
|
121
|
+
sc.nextLine();
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
```
|