// Sum of digits of given number
public class SumOfDigits
{
public static void main(String[] args)
{int i=521;
int sum=0;
while(i>0)
{
int r=i%10;
sum=sum+r;
i=i/10;
}
System.out.println("Sum of digits of 521 is "+sum);
}
}
Output:Sum of digits of 521 is 8