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

Recommended Answers

All 4 Replies

For the user input part, see this snippet.

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.

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

commented: Very generous, considering the zero effort from the OP +15
commented: Free fish. +11

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. ;)

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.