qq_28499671 于 2015.05.26 15:18 提问

JAVA题目，求解答，求代码！！！！

6个回答

u012083961   2015.05.26 15:35

qq_28499671 额，我以为你是大神

tongyi55555   2015.05.26 15:53
``````public class Point {
private int xValue;
private int yValue;

public Point(int xValue, int yValue) {
this.setxValue(xValue);
this.setyValue(yValue);
}

public double distance(Point point) {
double distance = Math.sqrt(Math.pow((point.getxValue() - this.xValue),
2) + Math.pow((point.getyValue() - this.yValue), 2));
return distance;
}

/**
* @return the xValue
*/
public int getxValue() {
return xValue;
}

/**
* @param xValue
*            the xValue to set
*/
public void setxValue(int xValue) {
this.xValue = xValue;
}

/**
* @return the yValue
*/
public int getyValue() {
return yValue;
}

/**
* @param yValue
*            the yValue to set
*/
public void setyValue(int yValue) {
this.yValue = yValue;
}

/*
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "点(" + this.xValue + "," + this.yValue + ")";
}

public static void main(String[] args) {
Point pointA = new Point(3, 4);
Point pointB = new Point(5, 6);
double distance = pointA.distance(pointB);
System.out.println(pointA.toString() + "与" + pointB.toString()
+ "之间的距离为：" + distance);
}
}
``````
Atlas_Scarlet   2015.05.26 15:54

class Point{
int x;
int y;
Point(int x,int y){
this.x=x;
this.y=y;
}
double distance(Point a,Point b){
return Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
}

guwei4037      2015.05.26 16:07
`````` public class Point {

private int _x;
private int _y;

public Point(int x, int y) {
this._x = x;
this._y = y;
}

public int get_x() {
return _x;
}

public void set_x(int _x) {
this._x = _x;
}

public int get_y() {
return _y;
}

public void set_y(int _y) {
this._y = _y;
}

public static double getDistance(Point p1, Point p2) {
int x = Math.abs(p2.get_x() - p1.get_x());
int y = Math.abs(p2.get_y() - p1.get_y());

return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
}
}

``````
`````` public class Test {

public static void main(String[] args) {
Point p1 = new Point(3, 4);
Point p2 = new Point(5, 6);

double distance = Point.getDistance(p1, p2);
System.out.println(distance);//2.8284271247461903
}
}

``````
u011114220   2015.05.26 16:12

class Point{

``````double x;
double y;

public Point(double x,double y){
this.x = x;
this.y = y;
}

public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}

public double distance(Point p){
double a = Math.abs(this.x - p.getX());
double b = Math.abs(this.y - p.getY());
return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
}
``````

}

u011114220   2015.05.26 16:12

class Point{

``````double x;
double y;

public Point(double x,double y){
this.x = x;
this.y = y;
}

public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}

public double distance(Point p){
double a = Math.abs(this.x - p.getX());
double b = Math.abs(this.y - p.getY());
return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
}
``````

}