質問編集履歴

1

変更しました。

2020/03/10 12:10

投稿

ta.tatu
ta.tatu

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,383 +1,383 @@
1
+ ```import java.util.InputMismatchException;
2
+
3
+ import java.util.Random;
4
+
5
+ import java.util.Scanner;
6
+
7
+
8
+
9
+ public class test32 {
10
+
11
+
12
+
13
+ public static void main(String[] args) {
14
+
15
+ int win = 0;
16
+
17
+ int game = 3;
18
+
19
+
20
+
21
+ for(int i = 0; i < game; i++) {
22
+
23
+ win += sub ();
24
+
25
+ }
26
+
27
+
28
+
29
+ System.out.println(game + "回勝負中、あなたは" + win + "回勝ちました。");
30
+
31
+ }
32
+
33
+
34
+
35
+ static Scanner stdIn = new Scanner(System.in);
36
+
37
+ static Random rand = new Random();
38
+
39
+
40
+
41
+ private static int sub() {
42
+
43
+ String[] com1 = new String[] {"グー", "チョキ", "パー"};
44
+
45
+ int hantei = 0;
46
+
47
+
48
+
49
+ while(true) {
50
+
51
+
52
+
53
+ while(true) {
54
+
55
+ System.out.println("じゃんけん勝負\n3回勝負です\n\n初めにじゃんけん!です\n数字で入力してね");
56
+
57
+ System.out.println("0:グー\n1:チョキ\n2:パー\n");
58
+
59
+
60
+
61
+ System.out.print("最初はグー、じゃんけん : ");
62
+
63
+
64
+
65
+ try {
66
+
67
+ String str1 = stdIn.next();
68
+
69
+ int pry1 = Integer.parseInt(str1);
70
+
71
+ int cpu1 = rand.nextInt(3);
72
+
73
+
74
+
75
+ switch (pry1) {
76
+
77
+ case 0:
78
+
79
+ if (cpu1 == 0) {
80
+
81
+ System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "グーで… " + "あいこだよ!\n");
82
+
83
+ hantei = 0;
84
+
85
+ } else if (cpu1 == 1) {
86
+
87
+ System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "グーで… " + "あなたの勝ち\n");
88
+
89
+ hantei = 1;
90
+
91
+ } else {
92
+
93
+ System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "グーで… " + "あなたの負け\n");
94
+
95
+ hantei = 2;
96
+
97
+ }
98
+
99
+ break;
100
+
101
+ case 1:
102
+
103
+ if (cpu1 == 0) {
104
+
105
+ System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "チョキで… " + "あなたの負け\n");
106
+
107
+ hantei = 2;
108
+
109
+ } else if (cpu1 == 1) {
110
+
111
+ System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "チョキで… " + "あいこだよ!\n");
112
+
113
+ hantei = 0;
114
+
115
+ } else {
116
+
117
+ System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "チョキで… " + "あなたの勝ち\n");
118
+
119
+ hantei = 1;
120
+
121
+ }
122
+
123
+ break;
124
+
125
+ case 2:
126
+
127
+ if (cpu1 == 0) {
128
+
129
+ System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "パーで… " + "あなたの勝ち\n");
130
+
131
+ hantei = 1;
132
+
133
+ } else if (cpu1 == 1) {
134
+
135
+ System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "パーで… " + "あなたの負け\n");
136
+
137
+ hantei = 2;
138
+
139
+ } else {
140
+
141
+ System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "パーで… " + "あいこだよ!\n");
142
+
143
+ hantei = 0;
144
+
145
+ }
146
+
147
+ break;
148
+
149
+ default:
150
+
151
+ System.out.println("範囲外の数字です。0~2で入力してね。");
152
+
153
+ break;
154
+
155
+ }
156
+
157
+
158
+
159
+ if(hantei != 0) {
160
+
161
+ break;
162
+
163
+ }
164
+
1
- あっちむいてほいのあなたの負けを表示したいです。```java
165
+ }catch(NumberFormatException e) {
166
+
167
+ System.out.println("数字で入力してね。");
168
+
169
+ }
170
+
171
+ }
172
+
173
+
174
+
175
+ /*|----- ここまでが、じゃんけん!の領域 -----|*/
176
+
177
+
178
+
179
+ /*|----- ここから、あっちむいてホイ!の領域 -----|*/
180
+
181
+ String[] com2 = new String[] {"上", "下", "左", "右"};
182
+
183
+
184
+
185
+ while(true) {
186
+
187
+ System.out.println("次はあっちむいてホイ!です\n数字で入力してね");
188
+
189
+ System.out.println("0:上\n1:下\n2:左\n3:右\n");
190
+
191
+
192
+
193
+ System.out.print("始めるよ! あっちむいてホイ : ");
194
+
195
+ try {
196
+
197
+ String str2 = stdIn.next();
198
+
199
+ int pry2 = Integer.parseInt(str2);
200
+
201
+ int cpu2 = rand.nextInt(4);
202
+
203
+
204
+
205
+ switch (pry2) {
206
+
207
+ case 0:
208
+
209
+ if (cpu2 == 0) {
210
+
211
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "上だね\n");
212
+
213
+ if(hantei == 1) {
214
+
215
+ System.out.println("あなたの勝ち!");
216
+
217
+ return 1;
218
+
219
+ }else if(hantei == 2) {
220
+
221
+ System.out.println("あなたの負け!");
222
+
223
+ return 0;
224
+
225
+ }
226
+
227
+ } else if (cpu2 == 1) {
228
+
229
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "上だね\nもう一度じゃんけんからだよ!");
230
+
231
+ } else if (cpu2 == 2) {
232
+
233
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "上だね\nもう一度じゃんけんからだよ!");
234
+
235
+ } else if (cpu2 == 3) {
236
+
237
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "上だね\nもう一度じゃんけんからだよ!");
238
+
239
+ }
240
+
241
+ break;
242
+
243
+ case 1:
244
+
245
+ if (cpu2 == 0) {
246
+
247
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "下だね\nもう一度じゃんけんからだよ!");
248
+
249
+ } else if (cpu2 == 1) {
250
+
251
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "下だね\n");
252
+
253
+ if(hantei == 1) {
254
+
255
+ System.out.println("あなたの勝ち!");
256
+
257
+ return 1;
258
+
259
+ }else if(hantei == 2) {
260
+
261
+ System.out.println("あなたの負け!");
262
+
263
+ return 0;
264
+
265
+ }
266
+
267
+ } else if (cpu2 == 2) {
268
+
269
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "下だね\nもう一度じゃんけんからだよ!");
270
+
271
+ } else if (cpu2 == 3) {
272
+
273
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "下だね\nもう一度じゃんけんからだよ!");
274
+
275
+ }
276
+
277
+ break;
278
+
279
+ case 2:
280
+
281
+ if (cpu2 == 0) {
282
+
283
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "左だね\nもう一度じゃんけんからだよ!");
284
+
285
+ } else if (cpu2 == 1) {
286
+
287
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "左だね\nもう一度じゃんけんからだよ!");
288
+
289
+ } else if (cpu2 == 2) {
290
+
291
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "左だね\n");
292
+
293
+ if(hantei == 1) {
294
+
295
+ System.out.println("あなたの勝ち!");
296
+
297
+ return 1;
298
+
299
+ }else if(hantei == 2) {
300
+
301
+ System.out.println("あなたの負け!");
302
+
303
+ return 0;
304
+
305
+ }
306
+
307
+ } else if (cpu2 == 3) {
308
+
309
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "左だね\nもう一度じゃんけんからだよ!");
310
+
311
+ }
312
+
313
+ break;
314
+
315
+ case 3:
316
+
317
+ if (cpu2 == 0) {
318
+
319
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "右だね\nもう一度じゃんけんからだよ!");
320
+
321
+ } else if (cpu2 == 1) {
322
+
323
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "右だね\nもう一度じゃんけんからだよ!");
324
+
325
+ } else if (cpu2 == 2) {
326
+
327
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "右だね\nもう一度じゃんけんからだよ!");
328
+
329
+ } else if (cpu2 == 3) {
330
+
331
+ System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "右だね\n");
332
+
333
+ if(hantei == 1) {
334
+
335
+ System.out.println("あなたの勝ち!");
336
+
337
+ return 1;
338
+
339
+ }else if(hantei == 2) {
340
+
341
+ System.out.println("あなたの負け!");
342
+
343
+ return 0;
344
+
345
+ }
346
+
347
+ }
348
+
349
+ break;
350
+
351
+ default:
352
+
353
+ System.out.println("範囲外の数字です。0~3で入力してね。");
354
+
355
+ break;
356
+
357
+ }
358
+
359
+ }catch(InputMismatchException e) {
360
+
361
+ System.out.println("エラーです!0~3の数字で入力してね");
362
+
363
+ }catch(NumberFormatException e) {
364
+
365
+ System.out.println("エラーです!0~3の数字を入力してね");
366
+
367
+ }
368
+
369
+ return 0;
370
+
371
+ }
372
+
373
+ }
374
+
375
+ }
376
+
377
+ }
2
378
 
3
379
  コード
4
380
 
5
381
  ```
6
382
 
7
- import java.util.InputMismatchException;
8
-
9
- import java.util.Random;
383
+ あっちむいてほいのあなたの負けを表示したいです。
10
-
11
- import java.util.Scanner;
12
-
13
-
14
-
15
- public class test32 {
16
-
17
-
18
-
19
- public static void main(String[] args) {
20
-
21
- int win = 0;
22
-
23
- int game = 3;
24
-
25
-
26
-
27
- for(int i = 0; i < game; i++) {
28
-
29
- win += sub ();
30
-
31
- }
32
-
33
-
34
-
35
- System.out.println(game + "回勝負中、あなたは" + win + "回勝ちました。");
36
-
37
- }
38
-
39
-
40
-
41
- static Scanner stdIn = new Scanner(System.in);
42
-
43
- static Random rand = new Random();
44
-
45
-
46
-
47
- private static int sub() {
48
-
49
- String[] com1 = new String[] {"グー", "チョキ", "パー"};
50
-
51
- int hantei = 0;
52
-
53
-
54
-
55
- while(true) {
56
-
57
-
58
-
59
- while(true) {
60
-
61
- System.out.println("じゃんけん勝負\n3回勝負です\n\n初めにじゃんけん!です\n数字で入力してね");
62
-
63
- System.out.println("0:グー\n1:チョキ\n2:パー\n");
64
-
65
-
66
-
67
- System.out.print("最初はグー、じゃんけん : ");
68
-
69
-
70
-
71
- try {
72
-
73
- String str1 = stdIn.next();
74
-
75
- int pry1 = Integer.parseInt(str1);
76
-
77
- int cpu1 = rand.nextInt(3);
78
-
79
-
80
-
81
- switch (pry1) {
82
-
83
- case 0:
84
-
85
- if (cpu1 == 0) {
86
-
87
- System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "グーで… " + "あいこだよ!\n");
88
-
89
- hantei = 0;
90
-
91
- } else if (cpu1 == 1) {
92
-
93
- System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "グーで… " + "あなたの勝ち\n");
94
-
95
- hantei = 1;
96
-
97
- } else {
98
-
99
- System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "グーで… " + "あなたの負け\n");
100
-
101
- hantei = 2;
102
-
103
- }
104
-
105
- break;
106
-
107
- case 1:
108
-
109
- if (cpu1 == 0) {
110
-
111
- System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "チョキで… " + "あなたの負け\n");
112
-
113
- hantei = 2;
114
-
115
- } else if (cpu1 == 1) {
116
-
117
- System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "チョキで… " + "あいこだよ!\n");
118
-
119
- hantei = 0;
120
-
121
- } else {
122
-
123
- System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "チョキで… " + "あなたの勝ち\n");
124
-
125
- hantei = 1;
126
-
127
- }
128
-
129
- break;
130
-
131
- case 2:
132
-
133
- if (cpu1 == 0) {
134
-
135
- System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "パーで… " + "あなたの勝ち\n");
136
-
137
- hantei = 1;
138
-
139
- } else if (cpu1 == 1) {
140
-
141
- System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "パーで… " + "あなたの負け\n");
142
-
143
- hantei = 2;
144
-
145
- } else {
146
-
147
- System.out.println(com1[cpu1] + "(COM)と" + "(Player)" + "パーで… " + "あいこだよ!\n");
148
-
149
- hantei = 0;
150
-
151
- }
152
-
153
- break;
154
-
155
- default:
156
-
157
- System.out.println("範囲外の数字です。0~2で入力してね。");
158
-
159
- break;
160
-
161
- }
162
-
163
-
164
-
165
- if(hantei != 0) {
166
-
167
- break;
168
-
169
- }
170
-
171
- }catch(NumberFormatException e) {
172
-
173
- System.out.println("数字で入力してね。");
174
-
175
- }
176
-
177
- }
178
-
179
-
180
-
181
- /*|----- ここまでが、じゃんけん!の領域 -----|*/
182
-
183
-
184
-
185
- /*|----- ここから、あっちむいてホイ!の領域 -----|*/
186
-
187
- String[] com2 = new String[] {"上", "下", "左", "右"};
188
-
189
-
190
-
191
- while(true) {
192
-
193
- System.out.println("次はあっちむいてホイ!です\n数字で入力してね");
194
-
195
- System.out.println("0:上\n1:下\n2:左\n3:右\n");
196
-
197
-
198
-
199
- System.out.print("始めるよ! あっちむいてホイ : ");
200
-
201
- try {
202
-
203
- String str2 = stdIn.next();
204
-
205
- int pry2 = Integer.parseInt(str2);
206
-
207
- int cpu2 = rand.nextInt(4);
208
-
209
-
210
-
211
- switch (pry2) {
212
-
213
- case 0:
214
-
215
- if (cpu2 == 0) {
216
-
217
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "上だね\n");
218
-
219
- if(hantei == 1) {
220
-
221
- System.out.println("あなたの勝ち!");
222
-
223
- return 1;
224
-
225
- }else if(hantei == 2) {
226
-
227
- System.out.println("あなたの負け!");
228
-
229
- return 0;
230
-
231
- }
232
-
233
- } else if (cpu2 == 1) {
234
-
235
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "上だね\nもう一度じゃんけんからだよ!");
236
-
237
- } else if (cpu2 == 2) {
238
-
239
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "上だね\nもう一度じゃんけんからだよ!");
240
-
241
- } else if (cpu2 == 3) {
242
-
243
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "上だね\nもう一度じゃんけんからだよ!");
244
-
245
- }
246
-
247
- break;
248
-
249
- case 1:
250
-
251
- if (cpu2 == 0) {
252
-
253
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "下だね\nもう一度じゃんけんからだよ!");
254
-
255
- } else if (cpu2 == 1) {
256
-
257
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "下だね\n");
258
-
259
- if(hantei == 1) {
260
-
261
- System.out.println("あなたの勝ち!");
262
-
263
- return 1;
264
-
265
- }else if(hantei == 2) {
266
-
267
- System.out.println("あなたの負け!");
268
-
269
- return 0;
270
-
271
- }
272
-
273
- } else if (cpu2 == 2) {
274
-
275
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "下だね\nもう一度じゃんけんからだよ!");
276
-
277
- } else if (cpu2 == 3) {
278
-
279
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "下だね\nもう一度じゃんけんからだよ!");
280
-
281
- }
282
-
283
- break;
284
-
285
- case 2:
286
-
287
- if (cpu2 == 0) {
288
-
289
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "左だね\nもう一度じゃんけんからだよ!");
290
-
291
- } else if (cpu2 == 1) {
292
-
293
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "左だね\nもう一度じゃんけんからだよ!");
294
-
295
- } else if (cpu2 == 2) {
296
-
297
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "左だね\n");
298
-
299
- if(hantei == 1) {
300
-
301
- System.out.println("あなたの勝ち!");
302
-
303
- return 1;
304
-
305
- }else if(hantei == 2) {
306
-
307
- System.out.println("あなたの負け!");
308
-
309
- return 0;
310
-
311
- }
312
-
313
- } else if (cpu2 == 3) {
314
-
315
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "左だね\nもう一度じゃんけんからだよ!");
316
-
317
- }
318
-
319
- break;
320
-
321
- case 3:
322
-
323
- if (cpu2 == 0) {
324
-
325
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "右だね\nもう一度じゃんけんからだよ!");
326
-
327
- } else if (cpu2 == 1) {
328
-
329
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "右だね\nもう一度じゃんけんからだよ!");
330
-
331
- } else if (cpu2 == 2) {
332
-
333
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "右だね\nもう一度じゃんけんからだよ!");
334
-
335
- } else if (cpu2 == 3) {
336
-
337
- System.out.println(com2[cpu2] + "(COM)と" + "(Player)" + "右だね\n");
338
-
339
- if(hantei == 1) {
340
-
341
- System.out.println("あなたの勝ち!");
342
-
343
- return 1;
344
-
345
- }else if(hantei == 2) {
346
-
347
- System.out.println("あなたの負け!");
348
-
349
- return 0;
350
-
351
- }
352
-
353
- }
354
-
355
- break;
356
-
357
- default:
358
-
359
- System.out.println("範囲外の数字です。0~3で入力してね。");
360
-
361
- break;
362
-
363
- }
364
-
365
- }catch(InputMismatchException e) {
366
-
367
- System.out.println("エラーです!0~3の数字で入力してね");
368
-
369
- }catch(NumberFormatException e) {
370
-
371
- System.out.println("エラーです!0~3の数字を入力してね");
372
-
373
- }
374
-
375
- return 0;
376
-
377
- }
378
-
379
- }
380
-
381
- }
382
-
383
- }