Given a string, return a string where for every char in the original, there are two chars.

doubleChar("The") → "TThhee"
doubleChar("AAbb") → "AAAAbbbb"
doubleChar("Hi-There") → "HHii--TThheerree"

1
2
3
4
5
6
7
8
9
public String doubleChar(String str) {
  String character="";
  String result="";
  for (int i=0; i<str.length(); i++){
    character=str.substring(i,i+1);
    result=result+character+character;
  }
  return result;
}

Keresés

Ajánló