wkddudtjs20   4년 전

일단 String으로 받은 다음

char tmp = str.charAt(0);

str = str.replace(str.charAt(0), str.charAt(2));

str = str.replace(str.charAt(2), tmp);

이렇게 작성을 해봤는데 첫째자리랑 마지막자리랑 같은 값이 나오더라구요

처음 replace를 할 때 str.charAt(0)이랑 str.charAt(2)가 링크가 되는건가요?

123을 넣었을 때 tmp가 1이고

처음 replace했을 때 323 나오고

그다음 replace하니까 121가 나와요 ㅠㅠㅠㅠㅠ

주석은 값 확인하려고 사용하던 코드들입니다.

nahwasa   4년 전

  • replace

    public <a title="class in java.lang" href="../../java/lang/String.html">String</a> replace(char oldChar,
                          char newChar)
    Returns a string resulting from replacing all occurrences of oldChar in this string with newChar.

323에서 모든 3을 1로 바꾸신겁니닷

wkddudtjs20   4년 전

아..!!! 헐 정말 감사합니다!! 속 시원해졌어요

댓글을 작성하려면 로그인해야 합니다.