質問編集履歴
2
インデックスの入力と配列への入力を別にしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,9 +26,9 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
+
```before
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
import java.util.InputMismatchException;
|
32
32
|
|
33
33
|
import java.util.Scanner;
|
34
34
|
|
@@ -90,8 +90,80 @@
|
|
90
90
|
|
91
91
|
}
|
92
92
|
|
93
|
+
```after
|
93
94
|
|
94
95
|
|
95
|
-
コード
|
96
96
|
|
97
97
|
```
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
import java.util.InputMismatchException;
|
102
|
+
|
103
|
+
import java.util.Scanner;
|
104
|
+
|
105
|
+
public class Kadai1104 {
|
106
|
+
|
107
|
+
public static void main(String[] args) {
|
108
|
+
|
109
|
+
Scanner sc = new Scanner(System.in);
|
110
|
+
|
111
|
+
int[] nums = {-1,-1,-1,-1,-1};
|
112
|
+
|
113
|
+
int index = 0;
|
114
|
+
|
115
|
+
do {
|
116
|
+
|
117
|
+
try {
|
118
|
+
|
119
|
+
System.out.print("Index --> ");
|
120
|
+
|
121
|
+
index = sc.nextInt();
|
122
|
+
|
123
|
+
}catch(ArrayIndexOutOfBoundsException e) {
|
124
|
+
|
125
|
+
System.out.println("Index Error!");
|
126
|
+
|
127
|
+
System.out.println();
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
}while(index != -1);
|
132
|
+
|
133
|
+
do {
|
134
|
+
|
135
|
+
try {
|
136
|
+
|
137
|
+
System.out.print("Nums[" + index + "] --> ");
|
138
|
+
|
139
|
+
nums[index] = sc.nextInt();
|
140
|
+
|
141
|
+
}catch(InputMismatchException e){
|
142
|
+
|
143
|
+
System.out.println("Input Mismatch");
|
144
|
+
|
145
|
+
sc.next();
|
146
|
+
|
147
|
+
System.out.println();
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
}while(index != -1);
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
System.out.println();
|
158
|
+
|
159
|
+
for(int i=0; i<nums.length; i++) {
|
160
|
+
|
161
|
+
System.out.println("Nums[" + i + "] : " + nums[i]);
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
```
|
1
変更していません
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,25 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
下記の例のようにNums[2]を変えずに再入力をしたい
|
10
|
+
|
9
11
|
例: Index --> 2
|
12
|
+
|
13
|
+
Nums[2] --> a
|
14
|
+
|
15
|
+
Input Mismatch
|
16
|
+
|
17
|
+
Nums[2] --> b
|
18
|
+
|
19
|
+
Input Mismatch
|
20
|
+
|
21
|
+
Nums[2] --> c
|
22
|
+
|
23
|
+
Input Mismatch
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
10
28
|
|
11
29
|
|
12
30
|
|