Friday, June 8, 2012

WRITE A PROGRAM TO FIND THE SUM OF DIGITS OF A GIVEN NUMBER.?


♣♣ WRITE A PROGRAM TO FIND THE SUM OF DIGITS OF A GIVEN NUMBER. ♣♣



import java.io.*;
class pro3
{
            public static void main(String args[]) throws IOException
            {
            int num,rem,sum=0;
            InputStreamReader a=new InputStreamReader(System.in);
            BufferedReader b=new BufferedReader(a);
            System.out.print("Enter any numeric number : ");
            num=Integer.parseInt(b.readLine());
                        while(num!=0)
                        {
                        rem=num%10;
                        sum=sum+rem;
                        num=num/10;
                        }
            System.out.print("Sum of Number= "+ sum);
            }
}


OUTPUT :-

            Enter any numeric  number : 4652
            Sum of Number = 17

No comments:

Post a Comment