백준 11720

김경욱·2025년 6월 25일

백준

목록 보기
9/121

// click the icon in the gutter.

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);

    int count = in.nextInt();

    String values = in.next();

int total = 0 ;

        for (int i = 0; i < count; i++) {


            int each = values.charAt(i)-'0';
            total += each;

        }
    System.out.println(total);










}

}

이번 문제에서도 놀란점이 있다.
int each = values.charAt(i)-'0'; 이 부분이 내가 작성한 문자열에서 하나를 빼서 문자가 아닌 정수로 나타내기 위해 -'0'을 사용한게 인상깊었다.

0개의 댓글