String-2 > doubleChar
Problem: :
Given a string, return a string where for every char in the original, there are two chars.
Problem: :
Given a string, return a string where for every char in the original, there are two chars.
Test Cases:
doubleChar("The") → "TThhee"
doubleChar("AAbb") → "AAAAbbbb"
doubleChar("Hi-There") → "HHii--TThheerree"
doubleChar("AAbb") → "AAAAbbbb"
doubleChar("Hi-There") → "HHii--TThheerree"
Solution:
public String doubleChar(String str) {
String s=str,s1="";
for(int i=0;i<s.length();i++)
{
s1+=s.substring(i,i+1)+s.substring(i,i+1);
}
return s1;
}