Java Recursion Program Practise 5 - to input a number and print the sum of digits of the number
Java Program to input a number and print the sum of digits of the number using Recursive Function
import java.util.*;
class Main {
int digit(int n){
if(n==0)
return 0;
else
return (n%10+digit(n/10));
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a;
System.out.println("Enter the number whose sum of digit is desired using Recursive function");
a = in.nextInt();
Main ob = new Main();
System.out.println(ob.digit(a));
}
}
Comments
Post a Comment