galinyotsev123

ProgBasicsJavaBook7.1ComplexLoop09sumDigits

Jan 14th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class E09sumDigits {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8. int sum = 0;
  9.  
  10. do {
  11. sum = sum + (n % 10);
  12. n = n / 10;
  13. } while (n > 0);
  14.  
  15. System.out.println("Sum of digits: " + sum);
  16.  
  17.  
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment