Program to input any number and display the sum of its digits

class sumdigit
{

public void sum(int n)
{
int sum=0,q=1,r;
while(n!=0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
System.out.println("sum of digits is"+sum);
}
}