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

1. Member
Join Date
Sep 2012
Posts
68
Rep Power
0

## 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
Java 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 + " ");
}
}
}```

2. Member
Join Date
Sep 2012
Posts
44
Rep Power
0

## 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).

3. Member
Join Date
Sep 2012
Posts
68
Rep Power
0

## 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

4. ## 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.

5. Member
Join Date
Sep 2012
Posts
44
Rep Power
0

## 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.

6. Member
Join Date
Sep 2012
Posts
68
Rep Power
0

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

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?

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

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.

8. Senior Member
Join Date
Oct 2012
Posts
176
Rep Power
6

## 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.

9. ## 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. Member
Join Date
Oct 2012
Location
NE Iowa
Posts
11
Rep Power
0

## 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?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•