본문 바로가기

[BOJ] - JAVA

[백준] 11720 : 숫자의 합 JAVA 풀이

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String str = br.readLine();
        int sum = 0;
        
        for(int i=0;i<n;i++){
            sum +=str.charAt(i)-'0';
        }
        System.out.println(sum);
    }
}