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"
Solution: easy
more complicated solution with Character.toString() - https://www.javatpoint.com/java-char-to-string
doubleChar("The") → "TThhee"
doubleChar("AAbb") → "AAAAbbbb"
doubleChar("Hi-There") → "HHii--TThheerree"
Solution: easy
public String doubleChar(String str) { String str1 = ""; for (int i = 0; i < str.length(); i++) { str1 = str1 + str.charAt(i) + str.charAt(i); } return str1; }
more complicated solution with Character.toString() - https://www.javatpoint.com/java-char-to-string
for (int i=0; i<str.length();i++){ String strChar = Character.toString(str.charAt(i))+
Character.toString(str.charAt(i)); System.out.print(strChar); }
Komentarze
Prześlij komentarz