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 + " ");

}

}

}

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

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

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.

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.

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?

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.

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.

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

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?