回答編集履歴

3

ソースの修正

2018/03/31 14:50

投稿

退会済みユーザー
test CHANGED
@@ -18,21 +18,9 @@
18
18
 
19
19
  ```Java
20
20
 
21
- package midi;
21
+ public class Main{
22
22
 
23
-
24
-
25
-
26
-
27
- import java.util.Random;
28
-
29
- import java.util.Scanner;
30
-
31
-
32
-
33
- public class Midi{
34
-
35
- public static void main(String[] args) {
23
+ public static void main(String[] args) {
36
24
 
37
25
 
38
26
 
@@ -48,7 +36,7 @@
48
36
 
49
37
  flag[i] = 0; /*これは初期化です。*/
50
38
 
51
-          r_position[i] = 0;
39
+ r_position[i] = 0;
52
40
 
53
41
  }
54
42
 
@@ -56,13 +44,11 @@
56
44
 
57
45
  for(int j = 0; j < year[i].length(); j++){
58
46
 
59
- String line = year[i].substring(j,j + 1);
60
-
61
- if("R".equals(line)){
47
+ if('R' == year[i].charAt(j)){
62
48
 
63
49
  flag[i] = 1;
64
50
 
65
- r_position[i] = year[i].indexOf("R");
51
+ r_position[i] = year[i].indexOf("R");
66
52
 
67
53
  break;
68
54
 

2

ソースの修正

2018/03/31 14:50

投稿

退会済みユーザー
test CHANGED
@@ -48,6 +48,8 @@
48
48
 
49
49
  flag[i] = 0; /*これは初期化です。*/
50
50
 
51
+          r_position[i] = 0;
52
+
51
53
  }
52
54
 
53
55
  for(int i = 0; i < year.length ;i++) {
@@ -60,7 +62,7 @@
60
62
 
61
63
  flag[i] = 1;
62
64
 
63
- r_position[i] = year[i].indexOf("R"); ;
65
+ r_position[i] = year[i].indexOf("R");
64
66
 
65
67
  break;
66
68
 

1

ソースの修正

2018/03/31 14:38

投稿

退会済みユーザー
test CHANGED
@@ -16,13 +16,17 @@
16
16
 
17
17
 
18
18
 
19
- 自分なりにソースを書いてみました。
19
+ ```Java
20
20
 
21
- (check_rのところはListで書いたほうがいいかもしれません)
21
+ package midi;
22
+
23
+
22
24
 
23
25
 
24
26
 
25
- ```Java
27
+ import java.util.Random;
28
+
29
+ import java.util.Scanner;
26
30
 
27
31
 
28
32
 
@@ -32,27 +36,19 @@
32
36
 
33
37
 
34
38
 
35
- String[] year = {"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE",
39
+ String[] year = {"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE",
36
40
 
37
- "JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
41
+ "JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
38
42
 
39
43
  int []flag = new int[year.length];
40
44
 
41
- int [][]check_r = new int[year.length][9]; //スペルの最大値がSEPTEMBERの9
45
+ int []r_position = new int[year.length];
42
-
43
-
44
46
 
45
47
  for(int i = 0; i < year.length; i++){
46
48
 
47
49
  flag[i] = 0; /*これは初期化です。*/
48
50
 
49
- for(int j = 0; j < 9; j++){
50
-
51
- check_r[i][j] = 0;
52
-
53
- }
51
+ }
54
-
55
- }
56
52
 
57
53
  for(int i = 0; i < year.length ;i++) {
58
54
 
@@ -64,19 +60,17 @@
64
60
 
65
61
  flag[i] = 1;
66
62
 
63
+ r_position[i] = year[i].indexOf("R"); ;
64
+
67
- check_r[i][j] = 1;
65
+ break;
68
66
 
69
67
  }
70
68
 
71
- }
69
+ }
72
-
73
-
74
-
75
-
76
70
 
77
71
  }
78
72
 
79
- System.out.println("Rを含む月 および Rが場所はそれぞれ");
73
+ System.out.println("Rを含む月 および Rが最初に現れはそれぞれ");
80
74
 
81
75
  for(int i = 0; i < year.length; i++){
82
76
 
@@ -84,27 +78,11 @@
84
78
 
85
79
  System.out.print(i + 1 + "月:" + year[i] + " ");
86
80
 
87
- }
88
-
89
- for(int j = 0; j < 9; j++){
90
-
91
- if(check_r[i][j] == 1){
92
-
93
- System.out.print(j + 1 + "文字目 ");
81
+ System.out.println(r_position[i] + 1 + "文字目");
94
-
95
- }
96
-
97
- }
98
-
99
- if(flag[i] == 1){
100
-
101
- System.out.println();
102
82
 
103
83
  }
104
84
 
105
85
  }
106
-
107
-
108
86
 
109
87
  }
110
88