Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Program to read base and power and then calculate result of that expression using recursion in java

public class Digit_Sum 
{
    public static void main(String[] args) 
    {
        int n = 1230;
        int result = digit_sum(n);
        System.out.println("Sum:"+result);
    }
    public static int digit_sum(int n)
    {
        int sum = n % 10;
        if(n == 0)
        {
            return 0;
        }
        else
        {
             return sum + digit_sum(n / 10);
        }
 
    }
}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #Program #read #base #power #calculate #result #expression #recursion #java
ADD COMMENT
Topic
Name
3+5 =