
사진 출처 : https://www.acmicpc.net/

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int result = 0;
String[] M = new String[N];
String num = sc.next();
M = num.split("");
for (int i = 0; i < N; i++) {
result += Integer.parseInt(M[i]);
}
System.out.println(result);
}
}
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int result = 0;
String[] M = new String[N];
String num = sc.next();
M = num.split("");
숫자 입력 할 개수(N)와 입력한 숫자 간 합(result) 그리고 숫자 입력(M)을 설정, 숫자 간 공백이 없어야 하기 때문에 String 형으로 숫자를 입력 받은 뒤 공백 없이 끊어 주는 방법으로 선택했다.
for (int i = 0; i < N; i++) {
result += Integer.parseInt(M[i]);
}
System.out.println(result);
각각 숫자를 나눈 뒤, M을 String형으로 받은 뒤 숫자들을 쪼갯기 때문에 Integer형으로 바꾸고 합산을 진행했다.
