Determine the distance between point (x1, y1) and point (x2, y2), and assign the
ID: 3780977 • Letter: D
Question
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.
Challenge 2.7.1: Coordinate geometry Activity Determine the distance between point (x1, y1) and point (x2, y2), and assign the result to pointsDistance. The calculation is: Distance SquareRootof (x2 -x1? (y2-y1)2) You may declare additional variables. Ex: For points (1.0, 2.0) and (1.0, 5.0), pointsDistance is 3.0. 1 import java util Scanner 2 import java lang. Math 4 public class coordinateGeometry 5 public static void main (String [j args) f double x1 1.0 double y1 2.0 double x2 1.0 double y2 5.0 10 double pointsDistance 0.0 11 Your solution goes here 12 14 15 16 18 System.out.print ("Points distance: System. ou (pointsDistance); 19 20 21 return RunExplanation / 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 pointDistance=0.0; double xdif=x2-x1; //here x2-x1 is calculated double ydif=y2-y1; //here y2-y1 is calculated xdif=Math.pow(xdif,2); //here (x2-x1)2 is calculated ydif=Math.pow(ydif,2); //here (y2-y1)2 is calculated pointDistance=Math.sqrt(xdif+ydif); // square root of ((x2-x1)2+(y2-y1)2 System.out.print("Points Distance: "); System.out.println(pointDistance) return; } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.