回答編集履歴
2
anyMatchの引数間違い
test
CHANGED
@@ -90,13 +90,13 @@
|
|
90
90
|
|
91
91
|
public static String multiple(String word) {
|
92
92
|
|
93
|
-
if (Stream.of("s", "o", "x", "sh", "ch").anyMatch(word
|
93
|
+
if (Stream.of("s", "o", "x", "sh", "ch").anyMatch(word::endsWith)) {
|
94
94
|
|
95
95
|
return word + "es";
|
96
96
|
|
97
97
|
}
|
98
98
|
|
99
|
-
if (Stream.of("f", "fe").anyMatch(word
|
99
|
+
if (Stream.of("f", "fe").anyMatch(word::endsWith)) {
|
100
100
|
|
101
101
|
return word.substring(0, word.lastIndexOf('f')) + "ves";
|
102
102
|
|
1
閉じ括弧、条件が逆、Streamで作成
test
CHANGED
@@ -64,7 +64,7 @@
|
|
64
64
|
|
65
65
|
String end2 = word.substring(word.length() - 2, word.length() - 1);
|
66
66
|
|
67
|
-
if ("aiueo".contains(ends2)) {
|
67
|
+
if (!"aiueo".contains(ends2)) {
|
68
68
|
|
69
69
|
return word.substring(0, word.length() - 1) + "ies";
|
70
70
|
|
@@ -74,6 +74,48 @@
|
|
74
74
|
|
75
75
|
return word + "s";
|
76
76
|
|
77
|
+
}
|
78
|
+
|
77
79
|
}
|
78
80
|
|
79
81
|
```
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
multipleメソッドをStreamを使って書くとこうなりますか。
|
86
|
+
|
87
|
+
他にも別表現してます。
|
88
|
+
|
89
|
+
```java
|
90
|
+
|
91
|
+
public static String multiple(String word) {
|
92
|
+
|
93
|
+
if (Stream.of("s", "o", "x", "sh", "ch").anyMatch(word.endsWith(s))) {
|
94
|
+
|
95
|
+
return word + "es";
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
if (Stream.of("f", "fe").anyMatch(word.endsWith(s))) {
|
100
|
+
|
101
|
+
return word.substring(0, word.lastIndexOf('f')) + "ves";
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
if (word.endsWith("y") {
|
106
|
+
|
107
|
+
char end2 = word.charAt(word.length() - 2);
|
108
|
+
|
109
|
+
if ("aiueo".indexOf(end2) < 0) {
|
110
|
+
|
111
|
+
return word.substring(0, word.length() - 1) + "ies";
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
return word + "s";
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
```
|