/* ------------------------------------------------------------ TRU COMP 1131 Crystal Laing January 2017 Assignment 2, Question 2. DistanceXY.java This program reads two points (x, y) and computes the distance between them using the formula: Distance = (sqrt)[(x2-x1)^2 + (y2-y1^2)] ------------------------------------------------------------ */ // import libraries for Scanner class import java.util.Scanner; public class DistanceXY { public static void main(String[] args) { // declare variables for equation int x1; int x2; int y1; int y2; double Distance; Scanner scan = new Scanner(System.in); System.out.println("Enter the X coordinate of the first point: "); x1 = scan.nextInt(); System.out.println("Enter the Y coordinate of the first point: "); y1 = scan.nextInt(); System.out.println("Enter the X coordinate of the second point: "); x2 = scan.nextInt(); System.out.println("Enter the Y coordinate of the second point: "); y2 = scan.nextInt(); // Distance = (sqrt)[(x2-x1)^2 + (y2-y1^2)] Distance = Math.sqrt(Math.pow((x2-x1), 2) + Math.pow((y2-y1), 2)); System.out.println("The distance in units is: " + Distance); } }