Summation Of A Given Numbers Elements by using Java Program

Code:

import java.util.*;

public class Summation
{
   public static void main(String[] args)
   {
      int n,s=0;

      Scanner sc = new Scanner(System.in);

      System.out.print("\nEnter The Number : ");
      n = sc.nextInt();

      while(n!=0)
      {
             s=s+n%10;
 n=n/10;
       }
       System.out.println("\nThe Sum Of The Number Is : "+s+"\n");
   }
}

Output of program:


No comments

Powered by Blogger.