fork download
  1. import java.util.*;
  2.  
  3. class Ideone
  4. {
  5. static int sumOfDigits( int N ){
  6. int sum = 0;
  7. while( N>0 ){
  8. int digit = N%10;
  9. sum = sum+digit;
  10. N = N/10;
  11. }return sum;
  12. }
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. int result = sumOfDigits( 135 );
  16. System.out.println("135sum of digit :"+result);
  17. }
  18. }
Success #stdin #stdout 0.16s 55664KB
stdin
Standard input is empty
stdout
135sum of digit :9