 Now, here's an exercise. Given a set of points, an array of points, what is the closest point to the coordinate for two? One thing I want to take note of is, as you can see, I said I have a set of points, which means I have an array of points, which means I have a collection of data. Each one of these is its own row, and X and Y are their own columns. One thing to take note of is I do not want this guy to be the right answer. That will come back to haunt us in just a little bit. But from here, where's the closest point? Now, some of you are already playing I in this, and you're saying, oh, it's probably this one. Okay. Well, how do I get the computer to say the exact same thing? So, I've gone ahead and I've already started to flesh this out. And if we take a look at my code, the first thing you'll notice is that inside my main method, I went ahead and did that enumeration that we just talked about. And then I went ahead and designed out what my coordinate is. And then I built my multi-dimensional array. I went ahead and said points, and I presented out each one of these. So, point at zero is going to be negative one three, point at one, negative one, negative one, point at two, one one, point at three, two, zero point five. So I've already started to flesh this out. And I believe, if I'm not mistaken, yes, I've actually got a little bit of a typo there. It won't matter in the long run, but just for posterity's sake. Now you see, I come in here and I've got a little method called nearest point. Now that's where we're going to be working in just a bit. But then I print it out and I calculate out the distance just so we can see how far away it is as well. Now I've already built out my distance formula because, again, it's the distance formula. Hopefully you've already learned how to build this out from previous lectures and previous lectures. But now we get into nearest point. And I've only done a little bit to it. So you notice I've already got this closest point in here. But I want to go ahead and make that. I want to say what that is. So I'm actually going to come in here. And closest point, I'm actually going to set it equal to points at 0. Now why points at 0? Well, if we think about it, this by default, as soon as I start looking at my points, what I need to do is I'm going to look at each point, calculate out the distance between it and my coordinate, my coordinate for 2. And I'm going to go ahead and say, well, guess what? Since that is smaller than whatever my current distance is, you're the new distance. And just so we can see that, double, we'll call it closest dist, or equal distance from coordinate at x, coordinate at y, closest point at x, closest point at y. And I'm going to go ahead and just clean this up a little bit so that it looks a little bit more presentable. But there we are. Now again, if I don't check anything else, I already now have my closest point. I looked at one point, all right, that's the answer. Oh, no, it's not the answer. But now this is where we would build out our for loop because we have to traverse the array. So I would come in here and I'd say four int i less than or equal to zero i less than points dot length i plus plus. Now what I've gone ahead and done is now this is going to allow me to go through every one of my elements, zero, one, two, three, four, five, six, seven. So in order to work that, what I'm going to go ahead and need to do is I'm going to need to calculate out another distance, double dist is what I'll call it, distance. And this time I'm actually going to cheat and I'm going to just grab this stuff. The only difference is now instead of doing closest point, I'm dealing with points at i. Points at i constantly changes. It's going to go through and be zero, one, two, three, four, five, six, seven. Now that I have this distance, the next portion I need to do is if dist is less than closest dist. If I just found a shorter distance, a smaller distance, then what I currently have is my current best distance. That means I need to change things. My closest distance should now become dist and my closest point should become points at i. That is the coordinate that's smaller. So now let's go ahead and let's fire this up and let's have a look-see at this and see what happens. That's why I come in and I say java closest point dot java. Everything compiled out fine, that's good, java closest point. Now this is what I was talking about just a little earlier, notice 4, 2. I'm trying to find the closest point 2, 4, 2, but not including 4, 2. Now notice what it says, my distance is 0.0. So what that means is inside of this if statement down here, what I'm going to go ahead and add in is double ampersands. That allows me now to have a compound conditional statement. That compound conditional statement means this side has to be true and this side has to be true. And what I'm going to be looking at is that distance does not equal 0 or 0.0 if we're looking at doubles. But because that would indicate that I have the same coordinates. So now that I've saved that, this time let's take a look at what happens. And you will see this time instead of 4, 2, I get 3, 3 with a distance of 1, 4, 1, 4, 2, 1, blah, blah, blah, blah, blah. But that's because specifically I went distance does not equal 0, meaning when I get to this, calculate it out, see that it equals 0, skip it, move on to the next guy.