X1638: hasSuffix(word)?

Write the method boolean hasSuffix(String word) in Java that returns true if the string in word ends with one of these suffixes:

"er", "ity", "ment", or "ship"

If the end of the word has one of those suffixes, then return true, otherwise return false.

Note that you cannot use endsWith() to do the comparison.

You may consult the Java String class to help you solve this problem.

Examples:

hasSuffix("teacher") -> true
hasSuffix("creativity") -> true
hasSuffix("improvement") -> true
hasSuffix("computer") -> true

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.