public class Point
{
public int x;
public int y;
public Point(int x,int y)
{
this.x=x;
this.y=y;
}
public Point(int x)
{
this(x,x);
}
public double distance()
{
return this.distance(0,0);
}
public double distance(int x,int y)
{
return Math.sqrt((this.x-x)(this.x-x)+(this.y-y)(this.y-y));
}
public double distance(Point p)
{
return this.distance(p.x,p.y);
}
}
(3)编写一个测试类PointDemo,在该类中创建两个Point类的实例对象,即坐标点(3,3)和(4,5),并计算这两个点间的距离。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- qfl_sdu 2021-10-13 10:53关注
Point类:
public class Point { private double xx; private double yy; public Point(){xx = 0;yy=0;} public Point(double x,double y){xx =x;yy = y;} public double getXx() { return xx; } public void setXx(double xx) { this.xx = xx; } public double getYy() { return yy; } public void setYy(double yy) { this.yy = yy; } }
PointDemo类:
public class PointDemo { public static void main(String[] args) { // TODO Auto-generated method stub Point p1 = new Point(3,3); Point p2 = new Point(4,5); double dis = Math.sqrt((p1.getXx() - p2.getXx())*(p1.getXx() - p2.getXx()) + (p1.getYy()-p2.getYy())*(p1.getYy()-p2.getYy())); System.out.println("两点间的距离=" + dis); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 stm32代码移植没反应
- ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
- ¥100 连续两帧图像高速减法
- ¥15 组策略中的计算机配置策略无法下发
- ¥15 如何绘制动力学系统的相图
- ¥15 对接wps接口实现获取元数据
- ¥20 给自己本科IT专业毕业的妹m找个实习工作
- ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
- ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
- ¥50 mac mini外接显示器 画质字体模糊