➽ Program:-
import
java.util.*;
import
java.io.*;
public
class Main
{
public static void main(String args[])
{
long num, digit, sum = 0, temp;
Scanner s = new Scanner(System.in);
num = s.nextInt();
System.out.print("Enter the Number:
");
temp = num;
while(num > 0)
{
digit = num % 10;
sum
= sum + digit;
num /= 10;
}
System.out.print("Sum of the Digits
of " + temp + " = " + sum);
}
}
➽ Output:-
Enter the Number: 456789
Sum of the Digits of 456789 = 39
0 Comments
Please do not enter any spam link in the comment section.