## Problem:

Given a string, return a version without both the first and last char of the string. The string may be any length, including 0.

withouEnd2("Hello") → "ell"
withouEnd2("abc") → "b"
withouEnd2("ab") → ""

## Solution:

public String withouEnd2(String str) {  int len = str.length();  if (len < 3)    return "";  else    return str.substring(1,str.length()-1);}

1. public String withouEnd2(String str) {
if(str.length()==1)
return str = "";
if(str.length()>1)
str = str.substring(1,str.length()-1);
return str;
}

2. public String withouEnd2(String str) {

if(str.length() <= 1){
return "";
}

else{
String mid = str.substring(1,str.length() -1);
return mid;
}
}

3. public String withouEnd2(String str) {
return (str.length() <= 2)? "" : str.substring(1, str.length() - 1);
}

4. if (str.length()>2)
return str.substring(1,str.length()-1);

else
return "";

5. if(str.length() > 2) {
return str.substring(1, str.length()-1);
} else
return "";

1. where is the beginning
of the code

6. alternative solution :

public String withouEnd2(String str) {
String s1 = str , s2 = "";
int len = s1.length();
if(len <3){
s2= "";
}else{
s2= s1.substring(1,len-1);
}
return s2;
}