java 写出两点之间的距离
谢谢~~
很急~~ 展开
2013-11-11
import java.awt.Point;
public class JuLi {
public static void main(String[] args) {
Point p1 = new Point(5, 5);// 定义第一个点的坐标(5,5),或者你自己设置x,y坐标
Point p2 = new Point(6,6);// 定义第一个点的坐标(5,5),或者你自己设置x,y坐标
// 两点间距离
double jili = Math.sqrt(Math.abs((p1.getX() - p2.getX())
* (p1.getX() - p2.getX())+(p1.getY() - p2.getY())
* (p1.getY() - p2.getY())));
System.out.println("两点间的距离是:" + jili);
}
}
package com.qyx;
import java.util.Arrays;
class point {
double x;
double y;
double z;
point(double _x,double _y,double _z)
{
x=_x;
y=_y;
z=_z;
}
void setX(double _x){
x=_x;
}
void setY(double _y){
y=_y;
}
void setZ(double _z){
z=_z;
}
double getDistance(point P){
return (x-P.x)*(x-P.x)+(y-P.y)*(y-P.y)+(z-P.z)*(z-P.z);
}
}
public class pro2 {
public static void main(String[] args){
point p=new point(1.0, 2.0, 3.0);
point p1=new point(0.0, 0.0, 0.0);
System.out.println(p.getDistance(p1));
p.setX(5.0);
System.out.println(p.getDistance(new point(1.0,1.0,1.0)));
}
}
2013-11-11
import java.awt.Point;
public class Test {
public static void main(String[] args) {
Point p1=new Point(5,5);
Point p2=new Point(10,8);
double len=Math.sqrt(Math.abs(p1.getX()-p2.getX()));
System.out.println(len);
}
}