JAVA表示点的坐标并且用math.sqrt或math.hypot来计算两点间的距离
1.math.sqrt
import sheffield.*;
public class w {
public static void main(String[] args) {
EasyReader keyboard = new EasyReader();
double a = keyboard.readDouble("Please type first: ");
double b = keyboard.readDouble("Please type second: ");
double c = keyboard.readDouble("Please type third: ");
double d = keyboard.readDouble("Please type fourth: ");
System.out.println("pointA(" + a + "," + b + ")");
System.out.println("pointB(" + c + "," + d + ")");
double sum;
sum = Math.sqrt((a - c) * (a - c) + (b - d) * (b - d));
System.out.println(sum);
}
}
2.math.hypot
Math.hypot() 函数返回它的所有参数的平方和的平方根
import sheffield.*;
public class w {
public static void main(String[] args) {
EasyReader keyboard = new EasyReader();
double a = keyboard.readDouble("Please type first: ");
double b = keyboard.readDouble("Please type second: ");
double c = keyboard.readDouble("Please type third: ");
double d = keyboard.readDouble("Please type fourth: ");
System.out.println("pointA(" + a + "," + b + ")");
System.out.println("pointB(" + c + "," + d + ")");
double sum;
sum = Math.hypot(a - c, b - d);
System.out.println(sum);
}
}