Answers for "sum of digits of a number in java using recursion"

0

sum of digits java recursion

import java.util.Scanner;

public class SumDigit {
    public static void main(String[] argh){
        System.out.println("Enter int");
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int sum = 0 ;
        int i = 0;
        print( i =Sum_of_digits(sum,n));

    }

    public static int Sum_of_digits(int sum,int n){
        if(n<=0)
            return sum ;
        sum += n%10;

        return Sum_of_digits(sum,n/10);
    }

    public static void  print(int n){
        System.out.print(n);
    }
}
Posted by: Guest on July-13-2021
0

sum of digits java recursion

import java.util.Scanner;

public class SumDigit {
    public static void main(String[] argh){
        System.out.println("Enter int");
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int sum = 0 ;
        int i = 0;
        print( i =Sum_of_digits(sum,n));

    }

    public static int Sum_of_digits(int sum,int n){
        if(n<=0)
            return sum ;
        sum += n%10;

        return Sum_of_digits(sum,n/10);
    }

    public static void  print(int n){
        System.out.print(n);
    }
}
Posted by: Guest on July-13-2021

Code answers related to "sum of digits of a number in java using recursion"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language