Question: Write a program with a loop that asks the user to enter a series of even numbers. The user should enter the string done to

Write a program with a loop that asks the user to enter a series of even numbers. The user should enter the string done to signal the end of the series. After all the numbers have been entered, the program should display their sum. The program should ignore any number entered that is odd. A number is odd if the remainder is 1 if divided by 2. You will use the % operator to computer the remainder. For example, 3%2 would give you 1.
Hint: Read the input as a string using scaner.nextLine(). Compare the string with "done". To convert a string to a int, use Integer.parseInt(string). For example, int n = Integer.parseInt("5") converts the string "5" to the integer 5.
Sample run 1:
Enter a number (type 'done' to end):1
Enter a number (type 'done' to end):2
Enter a number (type 'done' to end):3
Enter a number (type 'done' to end):4
Enter a number (type 'done' to end):5
Enter a number (type 'done' to end):done
The sum is 6
Sample run 2:
Enter a number (type 'done' to end):-1
Enter a number (type 'done' to end):-2
Enter a number (type 'done' to end):10
Enter a number (type 'done' to end):-5
Enter a number (type 'done' to end):done
The sum is 8

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!