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".

Respuesta :

Answer:

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.