Advertisement
deyanmalinov

02. Sum Digits

Feb 13th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) {
  10.         Scanner scan = new Scanner(System.in);
  11.         String num = scan.nextLine();
  12.         int sum = 0;
  13.  
  14.         for (int i = 0; i < num.length(); i++) {
  15.             sum += num.charAt(i) - '0';
  16.         }
  17.         System.out.println(sum);
  18.     }
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement