Untitled
unknown
plain_text
2 years ago
744 B
6
Indexable
import java.lang.Math;
class DistanceCalculator {
private double x1, y1, x2, y2;
public DistanceCalculator(double x1, double y1, double x2, double y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public double calculateDistance() {
double distance = Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
return distance;
}
public static void main(String[] args) {
double x1 = 1.0, y1 = 2.0, x2 = 4.0, y2 = 5.0;
DistanceCalculator distanceCalculator = new DistanceCalculator(x1, y1, x2, y2);
double distance = distanceCalculator.calculateDistance();
System.out.println("Distance between points: " + distance);
}
}
Editor is loading...
Leave a Comment