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

Logic Gates for ISC Class 11: Truth Tables, Universal Gates, Half and Full Adder
ISC Class 11 Computer Science notes on logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR with truth tables, why NAND and NOR are universal gates, and half adder and full adder circuits with their Boolean expressions.
Decimal to Binary Conversion in Java: 3 Programs with Examples
How to convert a decimal number to binary on paper and in Java: three programs (String, place value and Integer.toBinaryString), binary to decimal, a dry run and common mistakes.

ISC Class 11 Computer Science Sample Paper 2026-27 with Solutions
A full 70-mark ISC Class 11 Computer Science sample paper for the 2026-27 annual exam: MCQs, number systems, propositional logic, logic gates, Java classes, arrays, strings, searching and sorting, and computing ethics, with complete worked solutions.