In this program, a number will be taken as input.
The sum of the digits of the number will be printed.
To know more about recursion check the given post.
https://java4school.com/recursion

import java.util.*;
class Recur
{
int sum=0;
int sumofdigits(int num)
{
if(num>0)
{
int r=num%10;
sum+=r;
sumofdigits(num/10);
}
return sum;
}
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number to print the sum of the digits");
int n=sc.nextInt();
Recur obj=new Recur();
System.out.println("The sum of the digits is "+ obj.sumofdigits(n));
}
}
Input:
Enter a number
123
The sum of the digits is 6