본문 바로가기
Algorithm

string split and append space

by ByteBridge 2018. 10. 9.
반응형


/* Implement loveSpace("abc") that returns "a b c" */
@Test
public static String loveSpace(String value){
if(value.length()<=0) return value;
StringBuilder sb = new StringBuilder();
char[] _value = value.toCharArray();
for(int i = 0;i<_value.length-1;i++){
sb.append(_value[i]).append(" ");
}
sb.append(_value[_value.length-1]);
return sb.toString();
}


반응형

'Algorithm' 카테고리의 다른 글

List and Stack  (0) 2018.10.20
Java - integer converto to bit and bit count  (0) 2018.10.20
checkPrimeNumber  (0) 2018.10.09
팰린드롬 (palindrome) 구현  (0) 2018.02.05
Java - 순열 ( Permutation )  (0) 2017.05.28