Menu

JAVA Program to calculate the sum of the digits and also number of digits in a number.


class sumofdigit
{
public static void main(String args[])
{
int sum = 0;
int count=0;
int n = 1254 ;
int t = n;
while (n > 0)
{
int p = n % 10;
sum = sum + p;
count++;
n = n / 10;
}
System.out.println("sum of the digits is" + sum);
System.out.println("number of digits is" + count);
}
}

No comments:

Post a Comment