인프런 커뮤니티 질문&답변
parseInt가 0을 제외하는 이유
작성
·
1.1K
0
퀴즈
What is the most efficient way to count the total number of specific characters in a string, ignoring case?
Iterate through the string and compare each character to both the uppercase and lowercase of the target character.
Convert the entire string to a single case (e.g., all uppercase) and count the characters.
Count uppercase and lowercase letters respectively and sum them.
Using a Set data structure, store characters without duplicates and then count them.
답변 1
6
만약 "023" 이라는 문자를
Integer.parseInt("023") 에 넣게되면
내부 구현에서는 0, 2, 3 이렇게 문자열을 char 단위로 순회하면서 * 10을 해주어 자릿수를 올리면서
값들을 모두 합쳐서 숫자 23을 만들게 됩니다.
예시로 보여드리면
result = 0,
1) '0' -> result = (result * 10) + 0 # result = 0
2) '2' -> result = (result * 10) + 2. # result = 2
3) '3' -> result = (result * 10) + 3. # result = 23
위와 같습니다.





