Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Ron McLeod
paul wheaton
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Himai Minh
Bartenders:
Forum:
Beginning Java
?? no idea
willl smith
Greenhorn
Posts: 2
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
finding the sum of the digits of k.
7+1+4+6 = 18
cheers
Ankush
Francis Siu
Ranch Hand
Posts: 867
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
int sum = 0; int k = 7146; do { sum = sum + k % 10; System.out.println (sum); k = k / 10; System.out.println (k); } while (k > 0); System.out.println (sum);
Francis Siu
SCJP, MCDBA
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
sum of two int arrays
while loop question
Fibonacci Sequence Problem
Sum Of Digits
Scanner class help
More...