teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

全体的にプログラムの数を減らしました。

2018/02/01 00:21

投稿

bd_
bd_

スコア21

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,4 @@
1
+ このプログラムの全体的な構造が分かりません。while文でループしていることは分かるのですがMath.Random()でどこからどこまでの乱数になるかが分かりません。
1
2
  for (int i = 0; i < answer.length; i++) {
2
3
  boolean flag = false;
3
4
  answer[i] = (int) (Math.random() * 6 + 1);
@@ -11,38 +12,4 @@
11
12
  }
12
13
 
13
14
  } while (flag == true);
14
- }
15
- while (true) {
16
- count++;
17
- System.out.println("*** "+count + "回目 ***");
18
- for (int i = 0; i < answer.length; i++) {
19
- System.out.print( (i + 1) + "個目 : ");
20
- try {
21
- input[i] = Integer.parseInt(br.readLine());
22
- } catch (NumberFormatException e) {
23
- System.err.println("数値を入力してください");
24
- i--;
25
- } catch (IOException e) {
26
- System.err.println("もう一度入力してください");
27
- i--;
28
- }
29
- }
30
- hit = 0;
31
- blow = 0;
32
- for (int i = 0; i < answer.length; i++) {
33
- for (int j = 0; j < answer.length; j++) {
34
- if (i == j && input[i] == answer[j]) {
35
- hit++;
36
- } else if (input[i] == answer[j]) {
37
- blow++;
38
- }
39
- }
40
- }
41
- System.out.println("ヒット" + hit + " ブロー" + blow);
42
- if (hit == 3) {
43
- System.out.println("おめでとー");
44
- break;
45
- }else{
46
- System.out.println();
47
- }
48
15
  }