java问题 定义一个Point点类
发布网友
发布时间:2022-04-22 06:36
我来回答
共3个回答
热心网友
时间:2023-08-10 03:24
public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public double distance(Point p1,Point p2){
return Math.sqrt((p2.getX()-p2.getX())*(p2.getX()-p2.getX())+(p2.getY()-p1.getY())*(p2.getY()-p1.getY()));
}
public static void main(String args[]){
Point p1 = new Point(14,17);
Point p2 = new Point(23,90);
double s = p1.distance(p1,p2);
System.out.println("2点之间的距离为:"+s);
}
}
热心网友
时间:2023-08-10 03:24
package test1;
public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x; }
public void setX(int x) {
this.x = x; }
public int getY() {
return y; }
public void setY(int y) {
this.y = y; }
public double distance(Point p1, Point p2){
return Math.sqrt((p2.getX()-p1.getX())*(p2.getX()-p1.getX())+(p2.getY()-p1.getY())*(p2.getY()-p1.getY()));
}
public void displayPoint (int x, int y){
System.out.println("x:"+x+",y:"+y);
}
public static void main(String args[]){
Point p1 = new Point(10,20);
Point p2 = new Point(35,25);
Point a1=new displaypoint(10,20);
a2= new displaypoint(35,25);
double s = p1.distance(p1,p2);
System.out.println("2点之间的距离为:"+s);
}
}
热心网友
时间:2023-08-10 03:24
public class Point {
private float x,y;
public Point(float x,float y){
this.x=x;
this.y=y;
}
public float getX() {
return x;
}
public void setX(float x) {
this.x = x;
}
public float getY() {
return y;
}
public void setY(float y) {
this.y = y;
}
public double distance(Point p){
return Math.sqrt((p.getX()-x)*(p.getX()-x)+(p.getY()-y)*(p.getY()-y));
}
}