编写一个表示平面上点的类MyPoint,成员变量和成员方法为: 5
doublex,y,表示x和y坐标MyPoint()MyPoint(doublex,doubley)doubledistance(MyPointmp),求两点之间的距离创...
doublex,y,表示x和y坐标
MyPoint() MyPoint(double x,double y)
double distance(MyPoint mp),求两点之间的距离
创建两个MyPoint对象,坐标分别为(3,4)和(8,9),并通过对象求这两点之间的距离 展开
MyPoint() MyPoint(double x,double y)
double distance(MyPoint mp),求两点之间的距离
创建两个MyPoint对象,坐标分别为(3,4)和(8,9),并通过对象求这两点之间的距离 展开
3个回答
展开全部
public class Mypoint
{
double x, y;
public Mypoint( double x0, double y0 ){
x = x0;
y = y0;
}
double distance( Mypoint mp )
{
return Math.sqrt( ( x - mp.x) * (x - mp.x ) + (y-mp.y) * (y-mp.y) );
}
public static void main(String[] args)
{
Mypoint a = new Mypoint( 3, 4 );
Mypoint b = new Mypoint( 8, 9 );
System.out.println( a.distance( b ));
}
}
{
double x, y;
public Mypoint( double x0, double y0 ){
x = x0;
y = y0;
}
double distance( Mypoint mp )
{
return Math.sqrt( ( x - mp.x) * (x - mp.x ) + (y-mp.y) * (y-mp.y) );
}
public static void main(String[] args)
{
Mypoint a = new Mypoint( 3, 4 );
Mypoint b = new Mypoint( 8, 9 );
System.out.println( a.distance( b ));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Mypoint
{
double x, y;
public Mypoint( double x0, double y0 ){
x = x0;
y = y0;
}
double distance( Mypoint mp )
{
return Math.sqrt( ( x - mp.x) * (x - mp.x ) + (y-mp.y) * (y-mp.y) );
}
public static void main(String[] args)
{
Mypoint a = new Mypoint( 3, 4 );
Mypoint b = new Mypoint( 8, 9 );
System.out.println( a.distance( b ));
}
}
{
double x, y;
public Mypoint( double x0, double y0 ){
x = x0;
y = y0;
}
double distance( Mypoint mp )
{
return Math.sqrt( ( x - mp.x) * (x - mp.x ) + (y-mp.y) * (y-mp.y) );
}
public static void main(String[] args)
{
Mypoint a = new Mypoint( 3, 4 );
Mypoint b = new Mypoint( 8, 9 );
System.out.println( a.distance( b ));
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
根据公式求距离呀!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询