Ask Question
10 August, 04:16

Write a method appendIfMissing which is passed a String s and a String e (for ending). If s doesn't already end with e, the method returns a new String which consists of the contents of s concatenated with e. It returns s otherwise.

For example, if s refers to the String "lightningbug" and e refers to the String "bug", the method returns "lightningbug".

If s refers to the String "Airplane II", and e refers to the String ": the Sequel", the method returns "Airplane II: the Sequel".

+4
Answers (1)
  1. 10 August, 05:28
    0
    public static String appendIfMissing (String s, String e) {

    if (! s. endsWith (e))

    return s+e;

    return s;

    }

    Explanation:

    Create a method called appendIfMissing takes two strings, s and e

    Inside the method, check if s ends with e - using endsWith method. If it is, append the to s and return the new string. Otherwise, return only the s

    *string1. endsWith (string2) method checks if the string1 ends with string2 and returns either true or false.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a method appendIfMissing which is passed a String s and a String e (for ending). If s doesn't already end with e, the method returns ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers