front3
Problem:
Test Cases:
front3("Java") → "JavJavJav"
front3("Chocolate") → "ChoChoCho"
front3("abc") → "abcabcabc"
Solution:
public String front3(String str) {
String re="";
if(str.length()>=3)
{
String k=str.substring(0,3);
re=k+k+k;
}
else if(str.length()<3)
{
re=str+str+str;
}
return re;
}
Problem:
Given a string, we'll say that the front is the first 3
chars of the string. If the string length is less than 3, the front is
whatever is there. Return a new string which is 3 copies of the front.
Test Cases:
front3("Java") → "JavJavJav"
front3("Chocolate") → "ChoChoCho"
front3("abc") → "abcabcabc"
Solution:
public String front3(String str) {
String re="";
if(str.length()>=3)
{
String k=str.substring(0,3);
re=k+k+k;
}
else if(str.length()<3)
{
re=str+str+str;
}
return re;
}
No comments:
Post a Comment