ZZULIOJ 1156: Singular to plural, Java

ZZULIOJ 1156: Singular to plural, Java

Question description

Enter a noun English word and convert the singular into the plural according to English grammar rules. The rules are as follows:
(1) If it ends with the consonant letter y, change y to i, and add es; (
2) If it ends with s, x, ch, sh, add es;
(3) If it ends with the vowel o, add es ;
(4) Add s in other cases.

enter

Enter a string containing only lowercase letters and no longer than 20 characters.

output

Output its corresponding plural form.

Sample inputCopy
butterfly
Sample outputCopy
butterflies
import java.io.*;

public class Main {
    
    
    public static void main(String[] args) throws IOException {
    
    
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        char[] s = bf.readLine().toCharArray();
        int len = s.length;
        if (s[len - 1] == 'y' && (s[len - 2] != 'a' || s[len - 2] != 'e' || s[len - 2] != 'i' || s[len - 2] != 'o' || s[len - 2] != 'u')) {
    
    
            s[len - 1] = 'i';
            bw.write(String.valueOf(s) + "es");
        } else if (s[len - 1] == 's' || s[len - 1] == 'x' || (s[len - 2] == 'c' || s[len - 2] == 's') && s[len - 1] == 'h')
            bw.write(String.valueOf(s) + "es");
        else if (s[len - 1] == 'o') bw.write(String.valueOf(s) + "es");
        else bw.write(String.valueOf(s) + "s");
        bw.close();
    }
}

Guess you like

Origin blog.csdn.net/qq_52792570/article/details/132609567