pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Java paste-bin - collaborative debugging tool View Help


Posted by Anonymous on Wed 10th Jan 21:13 (modification of post by Anonymous view diff)
diff | download | new post

  1. public int sumDigits(int n)
  2. {
  3.    String num = Integer.parseInt(n);   // n is passed to this function.
  4.  
  5.    int returnValue = 0; // our return value
  6.  
  7.    for (int i=0;i<num.length();i++) // We want to cycle through each character
  8.    {
  9.       returnValue += Integer.parseInt(num.substring(i,i)); // get just one character, aka one of the numbers and add it to the returnValue
  10.    }
  11.    return returnValue;  // return our value
  12. }

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings