Forum Moderators: open

Message Too Old, No Replies

Java Help for beginner! (Gaus formula)

         

matilda

11:51 am on Sep 25, 2001 (gmt 0)



Working with the Gaus formula:

n
(this funny
M lying on its side) = n* (n+1)
i=1 2

Here's my code for the formula, does anyone know why it doesn't work?

public class Gaus extends Object {
public static void main (String args()) {
short n;
short i = 0;
short result;
n = 10; //the first 10 numbers
for
System.out.println("the sum of numbers
1 to 10 = " + result);
}
}

And now I have to find the results for "n" in this table:

n= result
10
128
150
300
70000

Please help me, I'm an absolute beginner and this stuff is just way over my head!
thanx
M*

tedster

5:23 pm on Sep 25, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, matilda.

There may be two issues here:
1. What is the Gauss Formula
2. How to write the Java for it

I assume you're talking about Gauss's formula for the sum of the first n integers (the sideways M is a sigma, or sum sign). The formula for that sum is n*(n+1)/2. Not too complicated (Gauss figured it out in third grade!)

But that's as far as I can go; Java is a foreign country to me. Maybe a java jockey will come along and take this the rest of the way for you.

MikeFoster

5:22 am on Sep 28, 2001 (gmt 0)

10+ Year Member



result = n*(n+1)/2;
System.out.println("the sum of numbers 1 to 10 = " + result);

Also, check out this site:
[ugrad.math.ubc.ca...]