Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in java -Determine the distance between point (x1, y1) and point (x2, y2), and a

ID: 3667647 • Letter: I

Question

in java -Determine the distance between point (x1, y1) and point (x2, y2), and assign the result to pointsDistance. The calculation is: Distance = SquareRootOf( (x2 - x1)2 + (y2 - y1)2 ) You may declare additional variables. Ex: For points (1.0, 2.0) and (1.0, 5.0), pointsDistance is 3.0.

import java.util.Scanner;
import java.lang.Math;

public class CoordinateGeometry {
public static void main(String [] args) {
double x1 = 1.0;
double y1 = 2.0;
double x2 = 1.0;
double y2 = 5.0;
double pointsDistance = 0.0;
  


System.out.print("Points distance: ");
System.out.println(pointsDistance);

return;
}
}

Explanation / Answer

import java.util.Scanner;
import java.lang.Math;

public class CoordinateGeometry {
public static void main(String [] args) {
double x1 = 1.0;
double y1 = 2.0;
double x2 = 1.0;
double y2 = 5.0;
double pointsDistance = 0.0;


      pointsDistance = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); //distance calculation


System.out.print("Points distance: ");
System.out.println(pointsDistance);

return;
}
}

------------------------

output :

Points distance: 3.0