Advertisement
iLLcheff

SumDigits

Oct 8th, 2022
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int num = scanner.nextInt();
  8.         int num1 = num / 1000 % 10;
  9.         int num2 = num / 100 % 10;
  10.         int num3 = num / 10 % 10;
  11.         int num4 = num % 10;
  12.         int sum = num1 + num2 + num3 + num4;
  13.         System.out.println(sum);
  14.  
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement