Java Blog

 
 
 
import java.io.*;

class  SumOfDigit
{
    public static void main(String args[]) 
    {
          String str;
          int no,sum;
          sum=0;

          try{
                 BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                 System.out.print(\"Enter number to find it\'s Sum of Digit  :  \");
                 System.out.flush();
                  str=obj.readLine();
                 no=Integer.parseInt(str);

                     while(no > 0)
                     {
                         sum=sum+no;
                         no=no-1;
                    }

                System.out.println(\"Sum of Digit of Number \"+str+\"  is  \"+sum);
              }
        catch(Exception e)
        {}
    }
}