|
-
help with problem
Design and implement an application that reads an integer value and prints the //sum of all even integers between 2 and the input value, inclusive. Print an error message //if the input value is less than 2. Prompt accordingly.
Right now for the following problem i have this:
import java.util.Scanner;
public class Multiples
{
//-----------------------------------------------------------------
// Prints multiples of a user-specified number up to a user-
// specified limit.
//-----------------------------------------------------------------
public static void main (String[] args)
{
final int PER_LINE = 1;
int value, limit, mult, count = 0;
Scanner scan = new Scanner (System.in);
System.out.print ("Enter a value: ");
value = scan.nextInt();
limit = scan.nextInt();
mult = scan.nextInt();
System.out.println ();
System.out.println ("The sum of the even numbers between 2 and " + mult + " (inclusive) are:");
for (mult = value; mult <= limit; mult+= value)
{
System.out.print (mult + "\t");
count++;
if (count % PER_LINE == 0)
System.out.println();
}
}
}
as of right now all i can do is enter the value, hit return andnothing happens.
how can i after entering the value, it adds up all the even numbers between 2 and the value entered?
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