Computer Science, asked by Joydeep21, 1 year ago

Write a java code to print the sum of digits of a given number.


Joydeep21: ok 5pts is ok i tink
Sazz: hmm ok.

Answers

Answered by Sazz
3
class DigitSum
{
public static void main(String args[])
 {
int i,a=0, sum=0; i=Integer.parseInt(args[0]);
//choose you integer
(i!=0) { a=i%10; i=i/10; sum=sum+a;
}
System.out.println(sum);
  } 
Hope it helps you out (:
Similar questions