Java program to find the sum of the digits of a number


Program

public class DigitsSum
{

public static void main(String[] args)
{
int num=251025, rem = 0, sum = 0, temp;
temp = num;

while (num > 0)
{
rem = num % 10;
sum = sum + rem;
num = num / 10;
}

System.out.print("Sum of Digits of " + temp + " is " + sum);
}

}


Output

Sum of Digits of 251025 is 15



Related Post

Comments

BALACHANDRAN.V
         Easily to slove method &observed

©candidjava.com