Sum of the digits: An intriguing Recursion program
Sum of the digits: solved Java program for ISC Class 12 Computer Science with complete BlueJ code, explanation and sample output.
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.
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
Click the given link
Armstrong Number with Recursion
Binary Search
watch basic java videos here
www.youtube.com/user/trushntej

Related Posts
Continue learning with these related articles

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

Boolean Algebra for ISC Class 12: Laws, Canonical SOP and POS, and Simplification
ISC Class 12 Computer Science notes on Boolean algebra: all the laws and theorems, duality, De Morgan's laws, minterms and maxterms, converting to canonical SOP and POS, and step-by-step algebraic simplification with solved examples.