Results 21 to 40 of 42
 02042010, 09:18 AM #21Member
 Join Date
 Feb 2010
 Posts
 22
 Rep Power
 0
 02042010, 09:31 AM #22Member
 Join Date
 Feb 2010
 Posts
 22
 Rep Power
 0
Loops
I just think your wrong. I can not find anyway for it to print every number without ..."stupid loops"
 02042010, 10:36 AM #23Member
 Join Date
 Feb 2010
 Posts
 22
 Rep Power
 0
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);
}
 02042010, 10:46 AM #24
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,373
 Blog Entries
 7
 Rep Power
 25
 02042010, 10:51 AM #25
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,373
 Blog Entries
 7
 Rep Power
 25
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); }
kind regards,
JosLast edited by JosAH; 02042010 at 11:30 AM.
 02042010, 11:10 AM #26Member
 Join Date
 Feb 2010
 Posts
 22
 Rep Power
 0
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)
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 }
 02042010, 11:23 AM #27
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,373
 Blog Entries
 7
 Rep Power
 25
 02042010, 12:09 PM #28Member
 Join Date
 Feb 2010
 Posts
 22
 Rep Power
 0
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.
 02042010, 12:26 PM #29Member
 Join Date
 Jan 2010
 Posts
 26
 Rep Power
 0
..........
Last edited by JavaJuJitZu; 02042010 at 12:30 PM. Reason: Only read first page of thread, so reply was irrelevant
 02042010, 12:36 PM #30
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,373
 Blog Entries
 7
 Rep Power
 25
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
 02042010, 12:50 PM #31Member
 Join Date
 Feb 2010
 Posts
 22
 Rep Power
 0
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?
 02042010, 12:53 PM #32Member
 Join Date
 Feb 2010
 Posts
 22
 Rep Power
 0
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 thatLast edited by bigpips305; 02042010 at 12:56 PM.
 02042010, 01:04 PM #33
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,373
 Blog Entries
 7
 Rep Power
 25
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:* ** *** **** ***** ****** *******
Java Code:####### *###### **##### ***#### ****### *****## ******# *******
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
 02042010, 01:18 PM #34Member
 Join Date
 Feb 2010
 Posts
 22
 Rep Power
 0
okay.. i follow you on this..
Now even numbers?
 02042010, 01:27 PM #35
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,373
 Blog Entries
 7
 Rep Power
 25
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
 02042010, 01:41 PM #36Member
 Join Date
 Feb 2010
 Posts
 22
 Rep Power
 0
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.
 02042010, 02:08 PM #37Member
 Join Date
 Feb 2010
 Posts
 22
 Rep Power
 0
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 ;)
 02042010, 02:18 PM #38
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,373
 Blog Entries
 7
 Rep Power
 25
 02042010, 02:36 PM #39Member
 Join Date
 Feb 2010
 Posts
 22
 Rep Power
 0
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?
 02042010, 02:40 PM #40
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,373
 Blog Entries
 7
 Rep Power
 25
Similar Threads

netbeans: creating a jar including jar libraries
By satbobo in forum NetBeansReplies: 13Last Post: 08262009, 04:08 AM 
Jtable including picture
By JVposter in forum New To JavaReplies: 3Last Post: 02272009, 12:11 AM 
printing two smallest numbers from a series of numbers
By trofyscarz in forum New To JavaReplies: 2Last Post: 10142008, 11:46 PM 
Including JAR in applications
By bugger in forum New To JavaReplies: 0Last Post: 01112008, 10:36 AM 
Including HTML in a JLabel
By Java Tip in forum Java TipReplies: 0Last Post: 11272007, 10:56 AM
Bookmarks