计算两点间的距离
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
===========================
我上传的代码,测试结果是Wrong Answer
import java.util.Scanner;
public class Main {
double d;
double s;
double j;
double cald(double[] f) {
s = Math.pow((f[1] - f[3]), 2);
j = Math.pow((f[0] - f[2]), 2);
d = Math.sqrt(j + s);
return d;
}
public static void main(String[] args) {
Main oj = new Main();
double[][] f = new double[2][4];
double[] dc = new double[2];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < f.length; i++) {
for (int h = 0; h < f[i].length; h++) {
f[i][h] = sc.nextDouble();
}
dc[i] = oj.cald(f[i]);
System.out.println();
}
for (int i = 0; i < dc.length; i++) {
System.out.println(String.format("%.2f", (dc[i])));
}
}
}