|
-
Help With parameter passing
I have this program, I get the right answer but it does not do the right stuff, I'm supposed to take the SumOfN takes an int n as a parameter and returns the sum ofN, Method does not do this,
Your program should loop, ask for n, if N > 0, Calculate and Print sumofN
if N <= 0, stop
I've been working on this for 3 meesly hours and can't figure it out, pleaseeee help, So frustrated.
import java.util.*;
public class sumOfN {
//Method
public static int sumOfN(int n) {
return n;
}
// main(): application entry point
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
int count = 0;
int sum = 0;
System.out.println("Please enter an integer: ");
int n = stdin.nextInt();
//Return for zero and negative numbers
if (n <= 0) {
return;
}
//Calculate integer Value
for (count = n; count > 0; count--) {
sum += count;
}
//Print user input in an output form
System.out.println("SumOfN(" + n + ") has an integer value of " + sum);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks