int x = 15; //number to sum
int sum = 0;
while(x > 0)
{
sum += x%10;
x /= 10;
}
System.out.println(sum);
As for the user input, you should be able to do it yourself.
Type: Posts; User: Brt93yoda
int x = 15; //number to sum
int sum = 0;
while(x > 0)
{
sum += x%10;
x /= 10;
}
System.out.println(sum);
As for the user input, you should be able to do it yourself.