# Need help with finding the sum of a bunch of numbers.

• 10-06-2012, 02:18 AM
MrPosotive
Need help with finding the sum of a bunch of numbers.
Hey guys pretty much what i am doing is setting up a loop to add 3 in incriments of three to 9669. well the easy part was making the loop to add three to three untill it gets to 9669 but i have no idea how to do that. help please
Code:

```public class Prog152a {         public static void main(String args[])         {                 int b = 3;                 int c = 3;                 for(int a = 3; a <= 3223;a++){                 b =b + c;                                         System.out.println(b + " ");                 }         } }```
• 10-06-2012, 02:27 AM
Games2Design
Re: Need help with finding the sum of a bunch of numbers.
Could you explain in a different way what you want? Because i can't understand what you (my fault).
• 10-06-2012, 02:31 AM
MrPosotive
Re: Need help with finding the sum of a bunch of numbers.
ok so as you can see by running the program *if you do or dont ill explain anyway* it prints out numbers from 3 to 9669 in increments of three, i need to find out how to add all of those numbers up and print out the sum
• 10-06-2012, 02:44 AM
Fubarable
Re: Need help with finding the sum of a bunch of numbers.
All you need to do is declare a sum variable before the loop, and add b to the sum variable.
• 10-06-2012, 02:45 AM
Games2Design
Re: Need help with finding the sum of a bunch of numbers.
I was about to say that. But unfortunately i did not understand the task because of my not so great english vocabulary.
• 10-06-2012, 02:53 AM
MrPosotive
Re: Need help with finding the sum of a bunch of numbers.
Quote:

Originally Posted by Fubarable
All you need to do is declare a sum variable before the loop, and add b to the sum variable.

Hmm im not sure how to do that would it just be b + b?
• 10-06-2012, 03:03 AM
Fubarable
Re: Need help with finding the sum of a bunch of numbers.
Quote:

Originally Posted by MrPosotive
Hmm im not sure how to do that would it just be b + b?

b is the variable that holds every 3rd int. No you need a new int variable, say called "sum" that holds the sum. Keep trying.
• 10-10-2012, 04:22 AM
Daryn
Re: Need help with finding the sum of a bunch of numbers.
so set a int like that c one you got there to be the sum. Then make the sum = the sum plus b.
• 10-25-2012, 09:57 AM
DarrylBurke
Re: Need help with finding the sum of a bunch of numbers.
@sjicho: We're all here to learn, and posting a complete code solution doesn't help anyone to learn, so I've deleted your post.

Please also go through http://www.java-forums.org/forum-gui...w-members.html and BB Code List - Java Programming Forum

db
• 10-25-2012, 10:08 AM
traisjames
Re: Need help with finding the sum of a bunch of numbers.
To me at least your code you posted looks good. Its looping and adding 3 to be then you output b. So what is it doing that you are not liking?