Home > Back-end >  Everyone a great god, and to ask why this code is run out distance result has been to zero
Everyone a great god, and to ask why this code is run out distance result has been to zero

Time:04-10

Package pro;

The import pro. Point. S;

The class point {
Double x, y;
Point () {}
Point (double x, double y) {
this.x=x;
this.y=y; }
Void the show () {
System. The out. Println (" (" + x + ", "+ y +") ");
}
Static class s {

Point p1, p2,
Double s;
S () {}
S (point p1, point p2) {
This. P1=p; This. P2=p2;
S=Math. SQRT ((p1) X-ray p2) x) * (p1) X-ray p2) x)
+ (p1) y - p2) y) * (p1) y - p2) y));

}
Void the show () {System. Out. Println (s); }
}
}

Public class dian {
Public static void main (String [] args) {
S s1=new (s);
Point p=new point (2, 3);
Point p2=new point (2, 5);
P1. The show ();
P2. The show ();
S1. The show ();
}
}

CodePudding user response:

S s1=new (s);
.
S1. The show ();
Instantiation s1, did not call the constructor, double s forever as the default value of 0.

 
The class point {
Double x, y;

Point () {
}

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

Void the show () {
System. The out. Println (" (" + x + ", "+ y +") ");
}

Static class s {

Point p1, p2,
Double s;

S () {
}

S (point p1, point p2) {
This. P1=p;
This. P2=p2;
S=Math. SQRT ((p1) X-ray p2) x) * (p1) X-ray p2) x) + (p1) y - p2) y) * (p1) y - p2) y));

}

Void the show () {
System.out.println(s);
}
}

Public static void main (String [] args) {
Point p=new point (2, 3);
Point p2=new point (2, 5);
P1. The show ();
P2. The show ();
S s1=new s (p1, p2);
S1. The show ();
}
}
  • Related