The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

what am I doing wrong here? as far as I can tell the problem is within the while loop but the math looks right. when it's run, it seems to be doing integer math instead of floating point math and I have no idea why. any help would be greatly appreciated! :/

Re: Very Beginner Questions. Loops. 2nd post

hey thanks for the response. basically the program should just ask for an integer and print out a sum. the sum will be determined by the user like the example in the quote the user chose 4 so the program went "1.0/1 + 1.0/2 + 1.0/3 + 1.0/4 and the sum was 2.08333333333. if this would perform the math using floating point it would be correct but for some reason my code keeps using integer math dropping the remainders forcing the output to forever be 1.0 :/

Re: Very Beginner Questions. Loops. 2nd post

okay I got it figured out. my math was right but what was happening was the loop kept doing the same equation over and over so it wasn't adding the 1st iteration to the 2nd to the 3rd and so on and so forth to get the sum of all of them. but it works now. i can post the code if necessary. if not, consider it solved