fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) throws Exception {
  6.  
  7. /* 통과한 소스 - input을 String형으로 입력받아 처리한 경우
  8.   Scanner sc = new Scanner(System.in);
  9. int N = sc.nextInt();
  10. sc.nextLine();
  11. String input = sc.nextLine();
  12.  
  13. int result = 0;
  14. for(int i = 0; i<input.length();i++) {
  15. result += input.charAt(i) - '0';
  16. }
  17. System.out.println(result);
  18.   */
  19.  
  20. /* 틀렸다고 하는 소스 - input을 한글자씩 입력받아 처리한 경우*/
  21. Scanner sc = new Scanner(System.in);
  22. int N = sc.nextInt();
  23.  
  24. int result = 0;
  25. for (int i = 0; i < N; i++) {
  26. result += System.in.read() - '0';
  27. }
  28.  
  29. System.out.println(result);
  30. }
  31.  
  32. }
  33.  
Success #stdin #stdout 0.1s 35460KB
stdin
1
1
stdout
-49