# 在 Java 中計算歐幾里得距離

Shiv Yadav 2024年2月15日

## 在 Java 中計算歐幾里得距離

``````import java.lang.Math.*;

public class DistPoint {
public static void main(String arg[]) {
int q1, q2, p1, p2;
double distance;
q1 = 2;
p1 = 3;
q2 = 4;
p2 = 5;
distance = Math.sqrt((q2 - q1) * (q2 - q1) + (p2 - p1) * (p2 - p1));
System.out.println("distance between two points:"
+ "(" + q1 + "," + p1 + "),"
+ "(" + q2 + "," + p2 + ")===>" + distance);
}
}
``````

``````import java.util.Scanner;

public class Distance {
public static void main(String arg[]) {
int q1, q2, p1, p2;
double distance;
Scanner newnum = new Scanner(System.in);

System.out.println("enter q1 point");
q1 = newnum.nextInt();

System.out.println("enter p1 point");
p1 = newnum.nextInt();

System.out.println("enter q2 point");
q2 = newnum.nextInt();

System.out.println("enter p2 point");
p2 = newnum.nextInt();

distance = Math.sqrt((q2 - q1) * (q2 - q1) + (p2 - p1) * (p2 - p1));

System.out.println("distance between two points:"
+ "(" + q1 + "," + p1 + "),"
+ "(" + q2 + "," + p2 + ")===>" + distance);
}
}
``````

Shiv is a self-driven and passionate Machine learning Learner who is innovative in application design, development, testing, and deployment and provides program requirements into sustainable advanced technical solutions through JavaScript, Python, and other programs for continuous improvement of AI technologies.

LinkedIn