Aim:- Write a program to sum of digits of a number.
Software used:- Notepad, Command prompt
Program coding:-
class sumdigit
{
public static void main(String args[])
{
int d,n,sum=0;
n = Integer.parseInt(args[0]);
do
{
d=n%10;
n=(int)n/10;
sum=sum+d;
}
while(n>0);
System.out.println("The number contains " + sum+" digits");
}
}
Output:-
0 Comments
if you have any problem, please let me know