Results 1 to 10 of 10
  1. #1
    MrPosotive is offline Member
    Join Date
    Sep 2012
    Posts
    68
    Rep Power
    0

    Default 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. #2
    Games2Design is offline Member
    Join Date
    Sep 2012
    Posts
    44
    Rep Power
    0

    Default 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. #3
    MrPosotive is offline Member
    Join Date
    Sep 2012
    Posts
    68
    Rep Power
    0

    Default 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. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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. #5
    Games2Design is offline Member
    Join Date
    Sep 2012
    Posts
    44
    Rep Power
    0

    Default 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. #6
    MrPosotive is offline Member
    Join Date
    Sep 2012
    Posts
    68
    Rep Power
    0

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

    Quote Originally Posted by Fubarable View Post
    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. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

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

    Quote Originally Posted by MrPosotive View Post
    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. #8
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    177
    Rep Power
    2

    Default 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. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default 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 Guide For New Members and BB Code List - Java Programming Forum

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    traisjames is offline Member
    Join Date
    Oct 2012
    Location
    NE Iowa
    Posts
    11
    Rep Power
    0

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

Similar Threads

  1. Finding the Min and Max of numbers
    By Alexis_DB in forum New To Java
    Replies: 6
    Last Post: 09-30-2012, 12:58 PM
  2. Replies: 8
    Last Post: 03-25-2011, 11:38 PM
  3. Random Numbers - finding least value
    By collwill in forum New To Java
    Replies: 16
    Last Post: 03-08-2011, 12:34 AM
  4. Replies: 11
    Last Post: 01-14-2011, 06:36 PM

Posting Permissions

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