Hi I am creating a house search programme. the objective of this programme is to sell houses within a range specified by the potential buyer. Now the buyer would type in the amount he is willing to spend and the houses closest to this range should be presented to him/her even if they are a long way off, so long as they are the closest.

"do my homework for me", probably.

Sorry, my question is, how do I compare the integer values (price) of the houses to a user defined integer and determine which has the closest value to the user defined integer.

With comparison operators and subtraction.

This would normally be done through a query to a database though, not in your Java code.

I am afraid the requirement is only through the java code. the logic eludes me.

Well at least give it a try. Post the code and all error/compile messages as well as what it does (not) do that you expected, once you have written something.

``````if (a - b > 0) {
// blah blah blah
}``````

Sheesh, how hard can it get?

you migh wanna do a binary search and keep some parameters until you find the closest ones
house1: \$10k
house2: \$25k
house3: &50k and so on and then search through the array or binary tree depending which one you wanna use to storage your data until you get the closest price
if you wanna compare the value i think you cant do (a - b > 0) you have to do eiher:

int dif = a - b;
if (dif > 0);

or

if ((a - b) > 0)

if you wanna compare the value i think you cant do (a - b > 0) you have to do eiher:

int dif = a - b;
if (dif > 0);

or

if ((a - b) > 0)

Wrong.

I'm sorry, but, take two minutes to perform a test and you can avoid making false assumptions like this.

Edit: I mean, both of your examples, of course, work, but so does the original, making your "workarounds" unnecessary (although I will often use the second myself, to make maintenance of the code, for some of the novice programmers we have here, clearer).

you migh wanna do a binary search and keep some parameters until

Keep in mind though, binary search will only be of use with ordered data. At this point, since the poster is not even sure how to find the nearest match, a binary search is probably only going to add unnecessary complication where he has no need of it.