Here you will get java program to find sum of digits of a number. For example if given digit is 125 then its sum will be 8.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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