计算两点间的距离


Problem Description

输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。

 
 
Input

输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。

 


Output

对于每组输入数据,输出一行,结果保留两位小数。

 


Sample Input

0 0 0 1 0 1 1 0

 


Sample Output

1.00 1.41

 


Author

lcy

AC代码: //注意输入是浮点类型。。。
import
java.text.DecimalFormat; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ double[] points = new double[4]; for (int i = 0; i < points.length; i++) { points[i] = sc.nextDouble(); } double result = Math.sqrt(Math.pow((points[2]-points[0]),2)+Math.pow((points[3]-points[1]),2)); double n = Double.parseDouble(new DecimalFormat("0.00").format(result)); System.out.printf("%.2f",result); System.out.println(); } } }
posted @ 2018-02-24 16:05  ixummer  阅读(237)  评论(0编辑  收藏  举报