Tuesday, 10 October 2017

java program calculate sum of element of number


import java.util.*;
public class numSums
{
 public static void main(String args[])
{
  Scanner p= new Scanner(System.in);
   int num,sum=0;
    System.out.println("Enter any number please :");
    num=p.nextInt();
    while(num!=0)
{
       sum+=num%10;
       num/=10;
}
       System.out.println("The sum of all the elements of number is :"+sum);
}}

      

0 comments:

Post a Comment