๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/12931?language=java
ํ์ด
import java.util.*;
public class Solution {
public int solution(int n) {
int answer = 0;
while(n > 0){
answer += n%10;
n/=10;
}
return answer;
}
}
String์ผ๋ก ๋ณํ ํ ๊ฐ๊ฐ์ ์๋ฆฌ์๋ฅผ ๋ํด๋ ๋์ง๋ง ๊ตณ์ด ๋ณํํ์ง ์๊ณ ๋ ํด๊ฒฐ ํ ์ ์๋ ๋ฌธ์ ์ด๋ค.
n์ 10์ผ๋ก ๋๋ ๊ฐ์ answer์ ๋ํด์ฃผ๊ณ ๋ ์ด์ ๋๋์ด ์ง์ง ์์ ๋ answer๋ฅผ returnํ๋ค.
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
โฌ [Programmers] [Java] [Level2] JadenCase ๋ฌธ์์ด ๋ง๋ค๊ธฐ (1) | 2023.12.23 |
---|---|
โฌ [Programmers] [Java] [Level2] ์ต๋๊ฐ๊ณผ ์ต์๊ฐ (0) | 2023.12.14 |
โฌ [Programmers] [Python] [Level3] ์ฌํ ๊ฒฝ๋ก (1) | 2023.05.10 |
โฌ [Programmers] [Python] [Level2] ์นด๋ ๋ญ์น (1) | 2023.05.10 |
โฌ [Programmers] [Python] [Level2] ์นด๋ ๋ญ์น (0) | 2023.04.17 |