I'm taking a Java class, and I need help with an assignment using loops. We're using Eclipse SDK. The point of the assignment is to take all even integers between 2 and 100 and find the sum. I started a new project and made a do-while loop, but I can't get the right formula. Could anyone please tell me the formula or say if I should use another type of loop?
Page 1 of 1
Need help with Java. Loops
#2
Posted 25 October 2008 - 09:01 PM
I don't like giving people answers to their homework, so I'm just going to speak in vague terms and you'll have to figure it out yourself:
Since you know how many loop iterations you need, I would generally not use a do-while loop, but another type. A simple check for evenness while keeping a running tally and you should be good.
Since you know how many loop iterations you need, I would generally not use a do-while loop, but another type. A simple check for evenness while keeping a running tally and you should be good.
#3
Posted 27 October 2008 - 04:15 PM
Thanks for the help, I finally got the answer today while experimenting with for loops. I do have a problem with a lab where the goal is to find the square, cube, and square root of a number, and then put it all into a table-like format.
EDIT: Never mind, figured it out. I needed to use EasyFormat.
EDIT: Never mind, figured it out. I needed to use EasyFormat.
Page 1 of 1