Use the Point class that comes with java
import java.awt.Point;//Refer to the Point class under the awt package. The function of this class is to represent the position in the coordinate space of (x,y) public class Distance { public static void main(String[] args) { Point p1 = new Point(5, 6);// Define the coordinates of the first point (5,6) Point p2 = new Point(7,8);// Define the coordinates of the second point (7,8) // Positioning coordinates System.out.println("The x coordinate of p1 is "+p1.getX()); System.out.println("p1's y coordinate is "+p1.getY()); System.out.println("p2's x coordinate is "+p2.getX()); System.out.println("p2's y coordinate is "+p2.getY()); // Calculate the distance between two points double juli = Math.sqrt(Math.abs((p1.getX() - p2.getX()))* (p1.getX() - p2.getX())+(p1.getY() - p2.getY()))* (p1.getY() - p2.getY()))); System.out.println("The distance between two points is:" + juli); } }Constructor
public class Point {double num1,num2;Point(double i,double j){num1=i;num2=j;}void getX(){System.out.println(num1);}void getY(){System.out.println(num2);}public static void main(String[] args){Point p1=new Point(5, 6);Point p2=new Point(7, 8);p1.getX(); //xy's coordinates p1.getY();p2.getX();/* * Formula omitted*/}}The above is the method of finding the distance between two points introduced this time. Thank you for your support to Wulin.com.