Write a Java program and compute the sum of the digits of an integer.Input integer=62and the sum of the digits is 9 code example
Example: Java program to find the sum of all the digits in the inputted number
long number, sum;
Scanner sc = new Scanner(System.in);
System.out.println("Enter any DIGIT number: ");
number = sc.nextLong();
sc.close();
// For Logic for adding all digits in the given number
for (sum = 0; number != 0; number /= 10) {
sum += number % 10;
}
System.out.println("ForLoop Sum of ALL digits: " + sum);