0

I want to write a java method that takes a string as word and that method will decide if the word is singular or plural.

For example:

  • Bus is Singular, Buses is Plural
  • Dog is Singular, Dogs is Plural

I tried to do something like this:

public static boolean isPlural( String word ) {
   boolean flag = true;

   //the problem is that most words ending with s are not actually plural, like: Status
   if( word.endsWith("s") || word.endsWith("es") ) {
      flag = true;
   } else {
      flag = false;
   }
        
   return flag;
}

This method works in few cases like Buses, Dishes, cabins etc. But it will fail in status, sparcatus, Mess, creates etc

Thank you.

Sikandar Sahab
  • 638
  • 3
  • 10
  • 27
  • 1
    Besides the actual question: You don't need flag at all in your code. Your code is a oneliner: `return word.endsWith("s") || word.endsWith("es");` – MoxxiManagarm Nov 18 '22 at 08:22

0 Answers0