Advertisement
Joreto

SumDigits

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