★★ Java の宿題ここで答えます Part 57 ★★
■ このスレッドは過去ログ倉庫に格納されています
0053デフォルトの名無しさん
2006/07/11(火) 17:33:35あんまりきれいじゃないけど、こんなかんじ
public static String toPresentForm(String word) {
String ieAfterConsonant = "(\\w*[^aeiou])ie(d|s)";
String thirdPersonSingular = "(\\w*)(es|s)";
String normalPastForm = "(\\w*)ed";
if (word.matches(ieAfterConsonant)) {
return word.replaceFirst(ieAfterConsonant, "$1y");
} elseif (word.matches(thirdPersonSingular)) {
return word.replaceFirst(thirdPersonSingular, "$1");
} else if (word.matches(normalPastForm)) {
return word.replaceFirst(normalPastForm, "$1");
}
return word;
}
■ このスレッドは過去ログ倉庫に格納されています