HW5.2

时间:2023-03-09 13:17:31
HW5.2

HW5.2

 import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);
         System.out.print("Enter the number: ");
         long number = input.nextLong();

         input.close();

         System.out.println("The sum of the number is " + sumDigits(number));
     }

     public static long sumDigits(long n)
     {
         if(n < 10)
             return n;
         else
             return n % 10 + sumDigits(n / 10);
     }
 }