martinvalchev

Sum Digits

Nov 22nd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.36 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SumDigits {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         int result = 0;
  8.         while (n > 0 ){
  9.             result += n % 10;
  10.             n /= 10;
  11.         }
  12.         System.out.println(result);
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment