Hi,
I'm not really sure exactly what all of the variables where for, but based on the initial question here is a solution.
Code:
package test;
import java.util.Scanner;
public class Main
{
//-----------------------------------------------------------------
// Prints multiples of a user-specified number up to a user-
// specified limit.
//-----------------------------------------------------------------
public static void main(String[] args)
{
int limit = 0;
int sum = 0;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a Limit: ");
limit = scan.nextInt();
System.out.println();
System.out.println("The sum of the even numbers between 2 and " + limit + " (inclusive) are:");
for (int count = 1; count <= limit; count++)
{
// Only add if even
if((count & 1)!= 1)
{
sum+=count;
System.out.println(count);
}
}
System.out.println("The sum is " + sum);
}
}
run it using java test/Main from an command window
Hope this helps
Cheers
Graham
Bookmarks