Program: import java.util.Scanner; public class SumOfDigits // Here we are taking class name as SumOfDigits { public static void main(String[] args) { Scanner input = new Scanner(System.in); // scanning the input from the user System.out.println(\"Enter number to find it\'s sum of Digits : \"); long n = input.nextLong(); int sum = sumDigits(n); // calling sumDigits(long n) method System.out.println(\"The sum of Digits of a number is: \" + sum);// printing value of sum } public static int sumDigits(long n) { int num = (int) (n); int sum = 0; // initializing value of sum to zero while (num > 0) { sum += num % 10; // Partition the given number into individual numbers num = num / 10; // divides until all digits in a number has been covered } //End of while loop return sum; }// End of sumDigits Method } Output: Enter number to find it\'s sum of Digits : 456 The sum of Digits of a number is: 15 Solution Program: import java.util.Scanner; public class SumOfDigits // Here we are taking class name as SumOfDigits { public static void main(String[] args) { Scanner input = new Scanner(System.in); // scanning the input from the user System.out.println(\"Enter number to find it\'s sum of Digits : \"); long n = input.nextLong(); int sum = sumDigits(n); // calling sumDigits(long n) method System.out.println(\"The sum of Digits of a number is: \" + sum);// printing value of sum } public static int sumDigits(long n) { int num = (int) (n); int sum = 0; // initializing value of sum to zero while (num > 0) { sum += num % 10; // Partition the given number into individual numbers num = num / 10; // divides until all digits in a number has been covered } //End of while loop return sum; }// End of sumDigits Method } Output: Enter number to find it\'s sum of Digits : 456 The sum of Digits of a number is: 15.