Question: Using Java Write a program with a loop that asks the user to enter a series of even numbers. The user should enter the string
Using Java
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 even.
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
Get step-by-step solutions from verified subject matter experts
