java program to find sum of digits of a number until a single digit is obtained 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);