📍 자릿수 더하기

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

입력을 정수형이 아니라 문자열로 받는다.

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