ZZULIOJ1013: 求两点间距离
题目描述
给定A(x1, y1), B(x2, y2)两点坐标,计算它们间的距离。
输入
输入包含四个实数x1, y1, x2, y2,分别用空格隔开,含义如描述。其中0≤x1,x2,y1,y2≤100。
输出
输出占一行,包含一个实数d,表示A, B两点间的距离。结果保留两位小数。
样例输入
1 1 2 2
样例输出
1.41
import java.util.Scanner;
public class Main {
private static Scanner input;
public static void main(String[] args) {
input = new Scanner(System.in);
int x1=input.nextInt();
int y1=input.nextInt();
int x2=input.nextInt();
int y2=input.nextInt();
double dist = Math.pow(x2-x1, 2) + Math.pow(y2-y1, 2); //调用库函数pow()计算平方
double d = Math.sqrt(dist);
System.out.println(String.format("%.2f",d ));
}
}