import java.io.*;
class simple_sum_of_digit_of_given_number
{
public static void main(String args[])
{
try
{
int sum=0,n,no,rem;
DataInputStream cin=new DataInputStream(System.in);
System.out.println("Enter a number to calculate its digit's sum = ");
n=Integer.parseInt(cin.readLine());
no=n;
while(no!=0)
{
rem=no%10;
sum=sum+rem;
no=no/10;
}
System.out.println(n+" of sum of digit is "+sum);
}
catch(Exception e)
{
System.out.println("wrong input");
}
}
}
No comments:
Post a Comment