If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

The thing is I don't know how to write the code for the method to take the user input, calculate and see if it is 0 and then stop the program or calculate if the answer is 5, get the sum 5 + 4 + 3 + 2 + 1 + 0, could you maybe show me some code that would do this? thanks a bunch.

First of, there is a very quick and very clean way to calculate the SumOfN.

in your example you used 5, which results iun the SumOfN being 1+2+3+4+5=15. This is the hard way of doing things. the fast way (which only works on even numbers, but I'll give a fix for that later) would be:

n=4; // sumOfN: 1+2+3+4=10
sumOfN=(n/2)*(n+1);

This works because:
1+4 = 5 (n+1)
2+3 = 5 (n+1)
This combination can be made n/2 times.

now, to make this work with odd numbers as well is very straightforward:

n=5; // SumOfN: 1+2+3+4+5=15
sumOfN=(((n-1)/2)*n)+n;

this works because:
1+4 = 5 (n)
2+3 = 5 (n)
this combination can be made (n-1)/2 times (twice in this case).

You can check if an int is odd by doing:
if ((i%2) == 1)
{
}

the % gives you the remainder after dividing by 2, which in case of an odd number would be 1.

Now in you case, this calculation would take place in your sumOfN method, which would take theint as parameter and return the calculated value.

But How?

But still how do I put it into method SumOfN and then Calculate it in SumOfN and then Pull it out of SUmOfN to be printed? that's what I can't figure out, is how to call the method sumOfN, put all the calculations in sumofN to print it out?

I've never done an input this way before myself, so I can't help you there.

The problem why the main can't read the sumOfN method is because it is private and you have put it in a different class then your main method. if you make it public, that should solve the problem.
(This is my fault I see, cause I made it private in my example).
making a static method private makes no sence though, since static is always called from outside the class itself.