File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

?? no idea

 
willl smith
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could someone please explain what is going on here:

int sum = 0;
int k = 7146;
do {
sum = sum + k % 10;
k = k / 10;
} while (k > 0);
System.out.println (sum);
 
Ankush Bhargava
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
finding the sum of the digits of k.
7+1+4+6 = 18

cheers
Ankush
 
Francis Siu
Ranch Hand
Posts: 867
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can add some println function to print the result out when the loop run everytime. And also you can add the counter to know more clearly, the 1 time is.....the 2 time is ......etc
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic