0

Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"

Here is the sample output that I want to achieve:
Enter value: 3
Enter value :8
Enter Value:1
Enter value: 6
Enter value: 3
Enter value: 4
Enter Value: -5
Highest even integer: 8

4
Contributors
4
Replies
34
Views
11 Months
Discussion Span
Last Post by brothman01
2

For the user input part, see this snippet.

https://www.daniweb.com/programming/code/506346/a-simpler-safer-alternative-to-java-util-scanner

Or google "Java input integer".

You'll need to declare an integer called highestEvenNumberEntered and initialize it to something less than the lowest legitimate even integer, so anything less than two. You'll also need an integer variable called userInput.

Set up a do---while loop. The exit condition should be when the user enters a non-positive value. Within the loop body, prompt the user to enter an integer and store that integer in userInput. If userInput is even, check the highestEvenNumberEntered value. If userInput is greater than this value, make highestEvenNumberEntered equal userInput.

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html

After the loop, check the value of highestEvenNumberEntered. If it is 2 or greater, print that value. If not, print "No Even Integer".

Edited by AssertNull: grammar

Votes + Comments
Free fish.
Very generous, considering the zero effort from the OP
0

Just figured I'd give an algorithm without the actual code instead of the "Put In Effort" link or ignoring the thread completely like I usually do as an experiment to see if the OP comes back. If the OP doesn't come back, I'll consider it a failed experiment and go back to my "Kids these days" responses, but who knows, maybe the OP will come back with code and a directed question on why his program isn't working or whatever. I've been having moderate success lately with this recently in my personal life, albeit with students I actually know personally, so it's different.

As an aside, shouldn't a "Free fish" comment be NEGATIVE feedback rather than positive? Not to give anyone any ideas or anything. ;)

0

yea post some code man. We'd be glad to help but post unless that first answer was already good enough in which case nvm

Edited by brothman01

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.