Advertisement
advictoriam

Untitled

Nov 27th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    This program reads in four double variables, x1, y1, x2, and y2,
  5.    which represent the end points of a line segments, namely,
  6.       x1 is the x-coordinate of the starting point,
  7.       y1 is the y-coordinate of the starting point,
  8.       x2 is the x-coordinate of the ending point, and
  9.       y2 is the y-coordinate of the ending point.
  10.    The length of the line segment joining (x1, y1) and (x2, y2)
  11.    is computed using the Pythagorean theorem.
  12. */
  13. public class Lines
  14. {
  15.    public static void main (String[] args)
  16.    {
  17.       // Read coordinates
  18.       Scanner in = new Scanner(System.in);
  19.       double x1 = in.nextDouble();
  20.       double y1 = in.nextDouble();
  21.       double x2 = in.nextDouble();
  22.       double y2 = in.nextDouble();
  23.  
  24.       // Compute and print out the length of the line segment
  25.  
  26.       double length = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  27.      
  28.       System.out.println(length);
  29.    }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement