📍 자릿수 더하기
입력을 정수형이 아니라 문자열로 받는다.
String N = sc.next();
✨ 전체코드 ✨
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
String N = sc.readLine();
int sum = 0;
for(int i=0; i<N.length(); i++) {
sum += N.charAt(i) - '0';
} System.out.println(sum);
}
}
🌀 성능
- 메모리 : 28,348 KB
- 시간 : 112 ms
'Algorithm > SWEA' 카테고리의 다른 글
[JAVA | SWEA] #2046 스탬프 찍기 (0) | 2023.12.04 |
---|---|
[JAVA | SWEA] #1545 거꾸로 출력해 보아요 🙃 (0) | 2023.12.04 |
[JAVA | SWEA] #2063 중간값 찾기 (0) | 2023.12.04 |
[JAVA | SWEA] #2068 최대수 구하기 (0) | 2023.12.03 |
[JAVA | SWEA] #2070 큰 놈, 작은 놈, 같은 놈 (0) | 2023.12.03 |