## Problem:

Given a string, return true if the first 2 chars in the string also appear at the end of the string, such as with "edited".

frontAgain("edited") → true
frontAgain("edit") → false
frontAgain("ed") → true

## Solution:

public boolean frontAgain(String str) {
if (str.length() < 2)
return false;
else if (str.substring(0,2).equals(str.substring(str.length()-2, str.length())))
return true;
else
return false;
}

1. Thaks for nice logic

2. Thaks for nice logic

3. Thank you
There is a solution

public boolean frontAgain(String str) {
return str.length()>=2 && str.substring(0, 2).equals(str.substring(str.length()-2, str.length()));
}

4. public boolean frontAgain(String str) {
if(str.length()>1 && str.charAt(0) == str.charAt(str.length()-2)
&& str.charAt(1) == str.charAt(str.length()-1))
return true;
else return false;
}

5. public boolean frontAgain(String str) {
if(str.length()>1 && str.substring(0,2).equals(str.substring(str.length()-2)))
return true;
else return false;
}

6. public boolean frontAgain(String str) {
if (str.length() < 2) return false;
if (str.endsWith(str.substring(0, 2))) return true;
else return false;
}

7. public boolean frontAgain(String str) {
if (str.length() < 2) return false;
if (str.endsWith(str.substring(0, 2))) return true;
else return false;
}

8. public boolean frontAgain(String str) {
if(str.length()<2){
return false;
}
String first2 = str.substring(0,2);
return str.startsWith(first2) && str.endsWith(first2);
}

9. public boolean frontAgain(String str) {
if(str.length()>1&&str.endsWith(str.substring(0,2)))
return true;
return false;
}

10. public boolean frontAgain(String str) {
return (str.length()>1&&str.endsWith(str.substring(0,2)));
}

11. public boolean frontAgain(String str) {
if(str.length()>1){
String a=str.substring(0,2);
String b=str.substring(str.length()-2,str.length());
if(a.equals(b)){
return true;
}else return false;
}else return false;

}

12. public boolean frontAgain(String str) {
if(str.length()<2){
return false;
}
return str.substring(0,2).equals(str.substring(str.length()-2));
}

13. public boolean frontAgain(String str) {
if (str.length()>1 && str.endsWith(str.substring(0,2))) {
return true;
}
return false;
}

14. public boolean frontAgain(String str) {
return (str.length()>=2 && (str.substring(0,2).equals(str.substring(str.length()-2))));
}