当前位置: 代码迷 >> Java相关 >> 求教两点坐标距离问题
  详细解决方案

求教两点坐标距离问题

热度:243   发布时间:2007-05-23 17:33:58.0
求教两点坐标距离问题
计算(x1, y1)和(x2, y2)两点之间的距离。所有的数和返回值都应该是double类型的。
搜索更多相关的解决方案: 坐标  距离  double  返回值  

----------------解决方案--------------------------------------------------------
用java.awt.geom.Point2D的distance方法:

distance

public static double distance(double x1,
                              double y1,
                              double x2,
                              double y2)
Returns the distance between two points.

Parameters:
x1 - the X coordinate of the first specified point
y1 - the Y coordinate of the first specified point
x2 - the X coordinate of the second specified point
y2 - the Y coordinate of the second specified point
Returns:
the distance between the two sets of specified coordinates.
Since:
1.2


----------------解决方案--------------------------------------------------------
还是无弄明白,请具体点。。。
----------------解决方案--------------------------------------------------------
import java.util.Scanner;
public class Jl{
public static void main(String []args){
Scanner sc=new Scanner(System.in);
a b=new a();
b.x1=sc.nextDouble();
b.y1=sc.nextDouble();
b.x2=sc.nextDouble();
b.y2=sc.nextDouble();
double ar=b.area();
System.out.println(ar);
}
}
class a{
double x1;
double y1;
double x2;
double y2;
double area(){
return (Math.sqrt((x1-x2)*(x1-x2))+(y1-y2)*(y1-y2));
}
}
----------------解决方案--------------------------------------------------------
知道了不???

----------------解决方案--------------------------------------------------------
这个会了,那个素数你搞好了无,还是弄不好,郁闷
----------------解决方案--------------------------------------------------------
哦 这个你急吗??

----------------解决方案--------------------------------------------------------
4楼的程序有一点小马虎 导致计算的结果不正确 改正后如下:
import java.util.Scanner;
public class Jl{
public static void main(String []args){
Scanner sc=new Scanner(System.in);
a b=new a();
b.x1=sc.nextDouble();
b.y1=sc.nextDouble();
b.x2=sc.nextDouble();
b.y2=sc.nextDouble();
double ar=b.area();
System.out.println(ar);
}
}
class a{
double x1;
double y1;
double x2;
double y2;
double area(){
return (Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
}

----------------解决方案--------------------------------------------------------
  相关解决方案