Implement distance formula in java

In this post, we will see how to implement distance formula between two points in java.

Formula to find distance between two points ( x1, y1) and (x2 , y2) is

d= sqrt( (x2-x1)^2+ (y2 – y1)^2)

Here is simple program to calculate distance between two points in java.

Here we have used math.sqrt to calculate square root.
When you run above program, you will get below output:

Distance : 5.0

That’s about how to implement distance formula in java.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *