## Problem:

Given a string, return true if it ends in "ly".

endsLy("oddly") → true
endsLy("y") → false
endsLy("oddy") → false

## Solution:

public boolean endsLy(String str) {
int len = str.length();
String ly = "ly";

if (len < 2)
return false;
else if (ly.equals(str.substring(len-2,len)))
return true;
else
return false;
}

1. This below code will also work.

public boolean endsLy(String str) {
if(str.length() <2 ){
return false;
}
if(str.substring(str.length()-2).equals("ly"))
return true;
else
return false;
}

2. public boolean endsLy(String str) {
if(str.length() < 2){
return false;
}
return(str.substring(str.length()-2).equals("ly"));
}

3. public boolean endsLy(String str) {
return str.endsWith("ly");
}

4. public boolean endsLy(String str) {
int len = str.length();

return (len>=2) && str.substring(len-2, len).equals("ly");

}

5. public boolean endsLy(String str) {
if(str.length()<2){
return false;
}else{
String a=str.substring(str.length()-2);
String ly="ly";
if(ly.equals(a)){
return true;
}return false;
}
}

6. public boolean endsLy(String str) {
if(str.length()<2){
return false;
}else{
String a=str.substring(str.length()-2);
String ly="ly";
if(ly.equals(a)){
return true;
}return false;
}
}

7. if(str.length() < 2) return false;

return (str.substring(str.length()-2).equals("ly"));

8. public boolean endsLy(String str) {
return (str.length()>1&&str.substring(str.length()-2,str.length()).equals("ly"));
}

9. public boolean endsLy(String str) { if(str.length()>=2) { if(str.substring(str.length()-2,str.length())==("ly")) { return true; } else { return false; } } else { return false; } }

10. what is the error..!explain in detail

11. public boolean endsLy(String str) {

int length=str.length();
if(length<2)
return false;
if(str.charAt(length-1)=='y' && str.charAt(length-2)=='l')
return true;
else
return false;
}

12. public boolean endsLy(String str) {
if(str.endsWith("ly")){
return true;
}else return false;
}

13. public boolean endsLy(String str) {
int len=str.length()-2;
if(str.length()<2) return false;
String s=str.substring(len);
if(s.equals("ly")){
return true;
}
return false;
}