public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("请输入两点坐标:");
Scanner sc = new Scanner(System.in);
double x1,y1,x2,y2;
double sum;
while(sc.hasNext()) {
x1 = sc.nextDouble();
y1 = sc.nextDouble();
x2 = sc.nextDouble();
y2 = sc.nextDouble();
//Math.sqrt返回一个数的平方根,Math.pow返回一个数的平方
sum = Math.sqrt(Math.pow((x1-x2), 2) + Math.pow((y1-y2), 2)) ;
System.out.println("两点之间的距离:"+String.format("%.2f", sum)); //保留两位小数
}
}
//结果
请输入两点坐标:2 3 5 9
两点之间的距离:6.71