public class Point {
protected int x,y;
public void setPoint(int x,int y) {
this.x=x;
this.y=y;
}
public int getx(){
return x;
}
public int gety(){
return y;
}
//Main method
public static void main(String[] args) {
Point p1=new Point();
Point p2=new Point();
p1.setPoint(3,4);
p2.setPoint(6,6);
System.out.println("p1和p2两点坐标分别为:");
System.out.print("p1("+p1.getx()+" ");
System.out.println(p1.gety()+")");
System.out.print("p2("+p2.getx()+" ");
System.out.println(p2.gety()+")");
}
}如何求两点间的距离啊?谢谢各位了 应该写在哪里?
protected int x,y;
public void setPoint(int x,int y) {
this.x=x;
this.y=y;
}
public int getx(){
return x;
}
public int gety(){
return y;
}
//Main method
public static void main(String[] args) {
Point p1=new Point();
Point p2=new Point();
p1.setPoint(3,4);
p2.setPoint(6,6);
System.out.println("p1和p2两点坐标分别为:");
System.out.print("p1("+p1.getx()+" ");
System.out.println(p1.gety()+")");
System.out.print("p2("+p2.getx()+" ");
System.out.println(p2.gety()+")");
}
}如何求两点间的距离啊?谢谢各位了 应该写在哪里?
{
return Math.sqrt(Math.pow(this.getx()-anotherPoint.getx(),2)+Math.pow(this.gety()-anotherPoint.gety(),2));
}
distance=((x1-x2)^2+(y1-y2)^2)^0.5