sum of digits java recursion

Solutions on MaxInterview for sum of digits java recursion by the best coders in the world

showing results for - "sum of digits java recursion"
Eilidh
02 Jun 2017
1import java.util.Scanner;
2
3public class SumDigit {
4    public static void main(String[] argh){
5        System.out.println("Enter int");
6        Scanner input = new Scanner(System.in);
7        int n = input.nextInt();
8        int sum = 0 ;
9        int i = 0;
10        print( i =Sum_of_digits(sum,n));
11
12    }
13
14    public static int Sum_of_digits(int sum,int n){
15        if(n<=0)
16            return sum ;
17        sum += n%10;
18
19        return Sum_of_digits(sum,n/10);
20    }
21
22    public static void  print(int n){
23        System.out.print(n);
24    }
25}
26