求教两点坐标距离问题
计算(x1, y1)和(x2, y2)两点之间的距离。所有的数和返回值都应该是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 pointy1
- the Y coordinate of the first specified pointx2
- the X coordinate of the second specified pointy2
- 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)));
}
}
----------------解决方案--------------------------------------------------------