Java Program to Find Sum of Digits of a Number

Here you will get java program to discover aggregate of digits of a number. For instance whenever given digit is 125 then its entirety will be 8.

class sum
{
	public static void main(String...s)
	{
		int n,i,sum=0;
		n=Integer.parseInt(s[0]);
		
		while(n!=0)
		{
			i=n%10;
			sum+=i;
			n/=10;
		}
		
		System.out.println(sum);
	}
}

Output

Java Program to Find Sum of Digits of a Number

Leave a Comment

error: Alert: Content is protected!!