java初学,谁给找找错

classmypoint{privatedoublex;privatedoubley;mypoint(){doublex=0;doubley=0;}mypoint(dou... class mypoint
{
private double x;
private double y;
mypoint()
{
double x=0;
double y=0;
}
mypoint(double x,double y)
{
this.x=x;
this.y=y;
}
void setx(double x)
{
this.x=x;
}
double getx()
{
return x;
}
void sety(double y)
{
this.y=y;
}
double gety()
{
return y;
}
static double distance(mypoint p1,mypoint p2)
{ double d=0;
d=Math.hypot((p1.getx()-p2.getx()),(p1.gety()-p2.gety()));
return d;
}
static double distance(mypoint p1)
{ double d=0;
d=Math.hypot((x-p1.getx()),(y-p1.gety()));
return d;
}
}
public class Mypoint1
{
public static void main(String args[])
{
mypoint r1=new mypoint();
mypoint r2=new mypoint();
static double x=0;
static double y=0;
r1.setx(3);
r1.sety(4);
r2.setx(7);
r2.sety(8);
System.out.println("(3,4)和(7,7)的距离为"+mypoint.distance(r1,r2));
System.out.println("(0,0)和(3,4)的距离为"+mypoint.distance(r1));

}

}
展开
 我来答
微前端
2014-04-09 · 超过45用户采纳过TA的回答
知道小有建树答主
回答量:143
采纳率:0%
帮助的人:89.6万
展开全部
//注意,静态方法中,不能调用非静态成员变量

package com.ptengine;

class mypoint {
private double x;
private double y;

mypoint() {
double x = 0;
double y = 0;
}

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

void setx(double x) {
this.x = x;
}

double getx() {
return x;
}

void sety(double y) {
this.y = y;
}

double gety() {
return y;
}

static double distance(mypoint p1, mypoint p2) {
double d = 0;
d = Math.hypot((p1.getx() - p2.getx()), (p1.gety() - p2.gety()));
return d;
}

static double distance(mypoint p1) {
double d = 0;
d = Math.hypot((0 - p1.getx()), (0 - p1.gety()));
return d;
}
}

public class Mypoint1 {
public static void main(String args[]) {
mypoint r1 = new mypoint();
mypoint r2 = new mypoint();
double x = 0;
double y = 0;
r1.setx(3);
r1.sety(4);
r2.setx(7);
r2.sety(8);
System.out.println("(3,4)和(7,7)的距离为" + mypoint.distance(r1, r2));
System.out.println("(0,0)和(3,4)的距离为" + mypoint.distance(r1));

}
}
追问
您可以给每个语句加个注释吗?刚开始学,实在是弄的我头晕
yugi111
2014-04-09 · TA获得超过8.1万个赞
知道大有可为答主
回答量:5.1万
采纳率:70%
帮助的人:1.4亿
展开全部
package zhidao;

class MyPoint
{
double x;
double y;

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

double distance ( MyPoint p1, MyPoint p2 )
{
return Math.hypot (( p1.x - p2.x ), ( p1.y - p2.y ));
}

double distance ( MyPoint p1 )
{
return Math.hypot (( 0 - p1.x ), ( 0 - p1.y ));
}
}

public class TestMyPoint
{
public static void main ( String args[] )
{
MyPoint r1 = new MyPoint (3, 4);
MyPoint r2 = new MyPoint (7, 8);
System.out.println ("(3,4)和(7,7)的距离为" + r1.distance (r1, r2));
System.out.println ("(0,0)和(3,4)的距离为" + r1.distance (r1));
}
}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式