Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 42
  1. #21
    bigpips305 is offline Member
    Join Date
    Feb 2010
    Posts
    22
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    The ellipses (...) are a (more or less) official notation for a continuation, so the sum of all even numbers starting at 2 and ending at 98 is written as:

    2+4+6+ ... +(2*49).

    The sum of the first 'n' numbers (this is the general case) is written as:

    1+2+3+ ... +n.

    Centuries (milleniums actually) ago it was discovered that this sum equals:

    n*(n+1)/2

    Try some small examples. So if the sum of the first 'n' numbers can be written as n*(n+1)/2 then twice this sum can be written as n*(n+1).

    So, the sum of the first even numbers up to 98 is:

    2+4+6+8+ ... +2*49 == 49*(49+1) == 49*50 == 2450.

    Comprendo?

    kind regards,

    Jos
    Why do you give an example of 1+2+3...? Why even bring it up?When you say.. "THIS SUM" what sum are you talking about. When you say first n numbers WHAT NUMBERS specifically? Twice the sum? Twice the sum of what?

  2. #22
    bigpips305 is offline Member
    Join Date
    Feb 2010
    Posts
    22
    Rep Power
    0

    Default Loops

    I just think your wrong. I can not find anyway for it to print every number without ..."stupid loops"

  3. #23
    bigpips305 is offline Member
    Join Date
    Feb 2010
    Posts
    22
    Rep Power
    0

    Default

    int sum = 0;
    for(int n = 0; n <= 98; n=n+2) //loops 49 times
    {
    sum = sum + n;
    System.out.print(n + " ");
    }
    System.out.print(sum);
    }

  4. #24
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by bigpips305 View Post
    I just think your wrong.
    Mathematics 101 isn't your favourite thing is it? ;-)

    kind regards,

    Jos

  5. #25
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by bigpips305 View Post
    I just think your wrong. I can not find anyway for it to print every number without ..."stupid loops"
    Sure, you'll need a loop to print out every single number; you won't need any loops if you want to calculate the sum of all those numbers or just the even numbers, but you just won't understand my proofs or examples.In Java it would have been (warning: complete spoilers ahead)

    Java Code:
    int sum1ton(int n) { return n*(n+1)/2; }
    int sumeven2ton(int n) {n/=2; return n*(n+1); }
    The first little method returns the value 1+2+3+...+n while the second little method returns 2+4+8+...+n (inclusive).

    kind regards,

    Jos
    Last edited by JosAH; 02-04-2010 at 10:30 AM.

  6. #26
    bigpips305 is offline Member
    Join Date
    Feb 2010
    Posts
    22
    Rep Power
    0

    Default Okay?

    Okay??

    For the 100th time, I dont know where you getting this 1+2+3 thing. I never even needed that. So your attempt to explain with an incomplete, fragmented sentence was just throwing me off.

    And I thought it was pretty clear early on that I DID need it to print all the "EVEN" numbers As WELL as the total.

    I tried cutting and pasting each of your methods in.
    This is what I get:

    Java Code:
    run:
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot return a value from method whose result type is void
            at ass42.Main.main(Main.java:18)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)
    "cannot return a value from method whos result type is void"

    This is what I have based on the other posters, clear and consice instructions that I actually learned somethign from, and is perfect minus the += at the end. I would like to get rid of the last plus. I learn better from example, not rabbit trails. I am deffinite your motive was sincere for me to figure it out on my own, but all you really did was make it difficult.

    Java Code:
    int sum = 0;
    for(int n = 0; n <= 98; n=n+2) //loops 49 times
    {
        sum = sum + n;
            System.out.print(n + "+"); //Prints each even number and an addition sign
        
    
    }
            System.out.println("= " + sum); //Prints final sum
        }

  7. #27
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by bigpips305 View Post
    Okay??

    For the 100th time, I dont know where you getting this 1+2+3 thing. I never even needed that.
    Rejecting everything you have never needed before is a very dangerous attitude. I'm out of this thread, you do it your way and please throw my two little methods away because you don't know how to use them and you never have needed them before.

    kind regards,

    Jos

  8. #28
    bigpips305 is offline Member
    Join Date
    Feb 2010
    Posts
    22
    Rep Power
    0

    Default Rejection

    I only rejected that because you were being intentially persistent on including that when I was having an obviously tough time with just the one.

    I dont know, it seems like your declaring a method within the main method here.. Im not even on methods.. I just need a simple loop. If your "COMPLETE spoiler" was what I was eventually suppose to acheive from your teaching style, Im not sure I would have ever got that. So feel free to not feel like you hindered me in anyway by showing off that you had some way of solving this equation in a method or without using a loop.

    And even if I did understand how to use these methods, they are wrong. They dont print the even numbers.

  9. #29
    JavaJuJitZu is offline Member
    Join Date
    Jan 2010
    Posts
    26
    Rep Power
    0

    Default

    ..........
    Last edited by JavaJuJitZu; 02-04-2010 at 11:30 AM. Reason: Only read first page of thread, so reply was irrelevant

  10. #30
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by bigpips305 View Post
    I only rejected that because you were being intentially persistent on including that when I was having an obviously tough time with just the one.

    I dont know, it seems like your declaring a method within the main method here.. Im not even on methods.. I just need a simple loop. If your "COMPLETE spoiler" was what I was eventually suppose to acheive from your teaching style, Im not sure I would have ever got that. So feel free to not feel like you hindered me in anyway by showing off that you had some way of solving this equation in a method or without using a loop.

    And even if I did understand how to use these methods, they are wrong. They dont print the even numbers.
    I am not a teacher, I simply volunteer here but my impression is that if you don't understand something you simply claim that the other person was wrong; I wasn't wrong but I'm not proud of it because it is all very old and solid knowedge, I simply studied it years ago. You were your own hindrance because of your stubborn attitude. Don't do that anymore because it'll kick back in the (near) future and it most certainly doesn't help when you want to learn how to program.

    I just gave you two simple methods that can calculate the end result without a loop; you didn't understand what I was talking about but simply copied and pasted the code without knowing what you were doing. Nothing wrong with that but your conclusion that I was wrong is incorrect.

    Jos

  11. #31
    bigpips305 is offline Member
    Join Date
    Feb 2010
    Posts
    22
    Rep Power
    0

    Default Thanks

    In conclusion..

    I didn't understand any of your suggestions or proof. I am sure they all come from sound, hard working, and experienced background. I just think your explanations are horrible. Perhaps point of reference issue. If it is standard for code to go in a code box that isn't how it is actually written in proper syntax, please show me how I am suppose to interpret it so I dont continue to do it incorrectly. When I give examples of HTML in code boxes to others on other forums, I put it exactly how it is suppose to be.. I guess I just wish you were more complete in your instruction. You spent more time negating "doing it for me" or how I was taking your instructions, you could have just given me one line of code. I could have disected it and actually learned something. I am sorry, but you wouldnt even answer specific questions I had in an attempt to TRY to understand your teaching. It doesnt matter how solid your background is, if your speaking in chinese and being overly vague in your instruction, and its obvious, I am not gonna catch on just because you point out that Im not catching on.

    The ellipses (...) are a (more or less) official notation for a continuation, so the sum of all even numbers starting at 2 and ending at 98 is written as:

    2+4+6+ ... +(2*49). <--Where did you get the 49 from. Where would I have gotten that from just reading instructions to write a program in Java that finds all even numbers between 0 and 98.

    The sum of the first 'n' numbers (this is the general case) is written as:

    1+2+3+ ... +n. <-- what is n here? You are adding n. Is n 1?

    Centuries (milleniums actually) ago it was discovered that this sum equals:

    n*(n+1)/2 <--what is "this sum" the sum from the previous example?

    Try some small examples. So if the sum of the first 'n' numbers can be written as n*(n+1)/2 then twice this sum can be written as n*(n+1).

    I cant try a small example if I dont understand the 3 previous sentences.

    So, the sum of the first even numbers up to 98 is: <--the FIRST even numbers??? isnt it all the even numbers???

    2+4+6+8+ ... +2*49 == 49*(49+1) == 49*50 == 2450. <-- is this 3 different things. I dont get this.

    Comprendo?

  12. #32
    bigpips305 is offline Member
    Join Date
    Feb 2010
    Posts
    22
    Rep Power
    0

    Default

    Ill ask a favor.. For the sake of this assignment, since I have already a working version now. Can you please start from the top. Explain to me the logic, and then show me each step in code... Explain some logic, then show more code, ultimatly the whole thing.

    So if your saying 2+4+ n = 49 or whatever
    the code is :

    etc... Maybe I will be able to see how you were trying to explain to me so I can actually learn what I was doing wrong. If I didnt want to believe that you were right, I wouldnt even bother.. I just need it explained more complete and with example step by step. PLEASE

    looking back.. I dont see how I would have ever stumbled upon the method way like your example from the information you gave. All you did was tell me the math. How do I write the syntax. what is the proper way to write that
    Last edited by bigpips305; 02-04-2010 at 11:56 AM.

  13. #33
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by bigpips305 View Post
    Ill ask a favor.. For the sake of this assignment, since I have already a working version now. Can you please start from the top. Explain to me the logic, and then show me each step in code... Explain some logic, then show more code, ultimatly the whole thing.

    So if your saying 2+4+ n = 49 or whatever
    the code is :

    etc... Maybe I will be able to see how you were trying to explain to me so I can actually learn what I was doing wrong. If I didnt want to believe that you were right, I wouldnt even bother.. I just need it explained more complete and with example step by step. PLEASE
    I'll try to explain how the ancient Greeks figured this all out and I'll use a simple example: suppose you want to add the numbers 1+2+3+4+5+6+7. You can do it the simple way and do six additions but you can also do this: take enough pebbles and arrange them like this:

    Java Code:
    *
    **
    ***
    ****
    *****
    ******
    *******
    Every '*' represents a pebble. Now I'l add just as many pebbles and use the following arangement:

    Java Code:
    #######
    *######
    **#####
    ***####
    ****###
    *****##
    ******#
    *******
    Both the '*'s and '#'s represent pebbles. There are 7x8 pebbles layed out in a rectangular shape; half of it is (7x8)/2 which is the sum of 1+2+3+4+5+6+7.
    So if I have to add those seven numbers I could've done: 7*(7+1)/2.

    Concluding, for every integer 'n' >= 0 the sum of all integers up to this value 'n' (whatever it is) is n*(n+1)/2.

    kind regards,

    Jos

  14. #34
    bigpips305 is offline Member
    Join Date
    Feb 2010
    Posts
    22
    Rep Power
    0

    Default

    okay.. i follow you on this..

    Now even numbers?

  15. #35
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by bigpips305 View Post
    okay.. i follow you on this..

    Now even numbers?
    Now you understand that sum of the numbers 1+2+3+ ... +n equals n*(n+1)/2. Multiply the numbers in that sum and that formula by two; you get:

    2*1+2*2+2*3+ ... +(2*n) equals 2+4+6+ ...+(2*n) equals n*(n+1)

    (try a few examples, e.g. n=5: 2+4+6+8+10 == 5*6). So if you have to add all the even number up to 98, the value of 'n' is 49 (see above). The sum of all those values is 49*50 which equals 2450. No loops needed.

    kind regards,

    Jos

  16. #36
    bigpips305 is offline Member
    Join Date
    Feb 2010
    Posts
    22
    Rep Power
    0

    Default Whoa

    Now you understand that sum of the numbers 1+2+3+ ... +n equals n*(n+1)/2. Multiply the numbers in that sum and that formula by two; you get:

    2*1+2*2+2*3+ ... +(2*n) equals 2+4+6+ ...+(2*n) equals n*(n+1)

    (try a few examples, e.g. n=5: 2+4+6+8+10 == 5*6). So if you have to add all the even number up to 98, the value of 'n' is 49 (see above). The sum of all those values is 49*50 which equals 2450. No loops needed.

    n=8 2+4+6+8+10+12+14+16 == 8*9



    I take the last number.. Divide it by 2. Add one to it and multiply them together and I get the answer. So i understand these concepts. I saw the pebble example and quite a few other examples at

    Techniques for adding the numbers 1 to 100 | BetterExplained a few days ago...

    Now... This is how I think of it at first when I am trying to find a way to solve this using computation, specifically Java.

    Take the higher integer and divide it by two:

    int number = 98;
    int n = number / 2;

    System.out.print(n*n+1)

    Okay.. I have an answer.. But how do I think about how I need to print all the even numbers in Java before the answer.

  17. #37
    bigpips305 is offline Member
    Join Date
    Feb 2010
    Posts
    22
    Rep Power
    0

    Default Side note

    On another note.. I thought it was interesting that I just bumped into this:

    Comparing 3 Integers and Displaying the Largest and smallest - Java answers

    What happened to your ethics ;)

  18. #38
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by bigpips305 View Post
    Take the higher integer and divide it by two:

    int number = 98;
    int n = number / 2;

    System.out.print(n*n+1)
    No, you forgot the parentheses:

    Java Code:
    System.out.println(n*(n+1));
    kind regards,

    Jos

  19. #39
    bigpips305 is offline Member
    Join Date
    Feb 2010
    Posts
    22
    Rep Power
    0

    Default

    Right... so I mean I had this on the first day.. How does this tie in with your method. How do I use the method you suggested, and how does it fit with this?

  20. #40
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by bigpips305 View Post
    Right... so I mean I had this on the first day.. How does this tie in with your method. How do I use the method you suggested, and how does it fit with this?
    I told you all this on the first day but you didn't understand it.

    kind regards,

    Jos

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Replies: 13
    Last Post: 08-26-2009, 04:08 AM
  2. Jtable including picture
    By JVposter in forum New To Java
    Replies: 3
    Last Post: 02-26-2009, 11:11 PM
  3. printing two smallest numbers from a series of numbers
    By trofyscarz in forum New To Java
    Replies: 2
    Last Post: 10-14-2008, 11:46 PM
  4. Including JAR in applications
    By bugger in forum New To Java
    Replies: 0
    Last Post: 01-11-2008, 09:36 AM
  5. Including HTML in a JLabel
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-27-2007, 09:56 AM

Posting Permissions

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