aspose file tools
The moose likes Beginning Java and the fly likes ?? no idea Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "?? no idea" Watch "?? no idea" New topic
Author

?? no idea

willl smith
Greenhorn

Joined: Dec 03, 2004
Posts: 2
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

Joined: Dec 03, 2004
Posts: 19
finding the sum of the digits of k.
7+1+4+6 = 18

cheers
Ankush
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
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


Francis Siu
SCJP, MCDBA
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: ?? no idea
 
Similar Threads
while loop question
Fibonacci Sequence Problem
sum of two int arrays
Scanner class help
Sum Of Digits