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)