CHALLENGE ACTIVITY 2.9.1: Coordinate geometry. Determine the distance between points (x1, y1) and point (x2, y2), and assign the result to point Distance. The calculation is: Ex: For points (1.0, 2.0) and (1.0, 5.0), points Distance is 3.0.

Respuesta :

ijeggs

Answer:

import java.util.Scanner;

public class TestClass {

   public static void main(String[] args) {

       Scanner input = new Scanner(System.in);

       System.out.println("Enter value for x1, x2, y1, y2");

       double x1 = input.nextDouble();

       double x2 = input.nextDouble();

       double y1 = input.nextDouble();

       double y2 = input.nextDouble();

       double xVal = Math.pow((x2-x1),2);

       double yVal = Math.pow((y2-y1),2);

       double distance = Math.sqrt(xVal+yVal);

       System.out.println(distance);

   }

}

Explanation:

The code is written in Java Programming Language.

This code simply implements the formula for the distance between two points given as

distance =[tex]\sqrt{(x2-x1)^{2}+(y2-y1)^{2} )}[/tex]

The scanner class is used to prompt and receive all the variables that are declared.

Note that we used two special Java methods (Math.pow and Math.sqrt)