amatur_barnamenevis
جمعه 03 تیر 1390, 11:24 صبح
سلام به دوستان
ايراد اين قطعه كد چيه؟
public class Point {
private int x;
private int y;
public Point(){
}
public double distance(Point p)
{
int d =(x - p.x)* (x-p.x) + (y-p.y)*(y-p.y);
return Math.sqrt(d);
}
public void printMe(){
System.out.println("(" + x + "," + y + ")");
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public static void main(String[] args) {
Point [] p = new Point[3];
for (int i = 1; i <= p.length(); i++) {
p[i-1].setX(i * 2);
p[i-1].setY(i * 5);
p[i-1].printMe();
System.out.println(p[i-1].distance(p[0]));
}
}
}
ايراد اين قطعه كد چيه؟
public class Point {
private int x;
private int y;
public Point(){
}
public double distance(Point p)
{
int d =(x - p.x)* (x-p.x) + (y-p.y)*(y-p.y);
return Math.sqrt(d);
}
public void printMe(){
System.out.println("(" + x + "," + y + ")");
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public static void main(String[] args) {
Point [] p = new Point[3];
for (int i = 1; i <= p.length(); i++) {
p[i-1].setX(i * 2);
p[i-1].setY(i * 5);
p[i-1].printMe();
System.out.println(p[i-1].distance(p[0]));
}
}
}