- Java program that
computes the
distance between
2 points:
import java.util.Scanner;
public class Distance
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
double x1, y1, x2, y2, distance;
// Read in the coordinates (x1,y1) and (x2,y2)
x1 = input.nextDouble();
y1 = input.nextDouble();
x2 = input.nextDouble();
y2 = input.nextDouble();
distance = Math.sqrt( Math.pow((x1-x2), 2)
+ Math.pow((y1-y2), 2) );
}
}
|
|