## Problem:

Given a string, return a new string made of 3 copies of the first 2 chars of the original string. The string may be any length. If there are fewer than 2 chars, use whatever is there.

extraFront("Hello") → "HeHeHe"
extraFront("ab") → "ababab"
extraFront("H") → "HHH"

## Solution:

public String extraFront(String str) {
if (str.length() < 2)
return str + str + str;
else {
String newString = str.substring(0,2);
return newString + newString + newString;
}
}

1. public String extraFront(String str) {
if(str.length()<2)
return str+str+str;
else return str.substring(0,2)+str.substring(0,2)+str.substring(0,2);
}

2. public String extraFront(String str) {
if(str.length() > 2)
str=str.substring(0,2);

return str+str+str;
}

3. public String extraFront(String str) {
String front = (str.length() <= 2)? str: str.substring(0, 2);
return front + front + front;
}

4. public String extraFront(String str) {
if(str.length()>=2){
String a=str.substring(0,2);
return a+a+a;
}if(str.length()<2 && str.length()>0){
String a=str.substring(0,1);
return a+a+a;
}else return "";

}

5. public String extraFront(String str)
{
if(str.length()-1 < 1)
{
return str + str + str;
}
else
{
String newstr = str.substring(0,2);
return newstr + newstr + newstr;
}
}

6. public String extraFront(String str) {
if (str.length()>2){
return str.substring(0,2)+str.substring(0,2)+str.substring(0,2) ;
}
else
return str + str + str;

}

7. public String extraFront(String str) {

String res = str.substring(0,Math.min(str.length(),2));
return res+res+res;
}

8. Another way

public String extraFront(String str) {
if (str.length() < 2) return String.join("", Collections.nCopies(3, str
));
return String.join("", Collections.nCopies(3, str.substring(0, 2)));
}