Find distance between two points on 2D surface
// 3. Find distance between two points on 2D surface
// Length of a line
class LineDistance {
public static void main(String[] args) {
// Point 1 (Starting point)
int x1 = 10;
int y1 = 20;
// Point 2 (Ending Point)
int x2 = 100;
int y2 = 120;
float distance = (float)Math.sqrt(Math.pow((y2 - y1), 2) + Math.pow((x2 - x1), 2));
System.out.println("Length of a line is " + distance);
}
}
// Length of a line
class LineDistance {
public static void main(String[] args) {
// Point 1 (Starting point)
int x1 = 10;
int y1 = 20;
// Point 2 (Ending Point)
int x2 = 100;
int y2 = 120;
float distance = (float)Math.sqrt(Math.pow((y2 - y1), 2) + Math.pow((x2 - x1), 2));
System.out.println("Length of a line is " + distance);
}
}
Comments
Post a Comment
Post Your Valuable Comments