Advertisement
Blonk

Untitled

Mar 10th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. public class Main
  2. {
  3.     public static void main( String[] args )
  4.     {
  5.         // test the formula a bit
  6.         double d1 = distance(-2,1 , 1,5);
  7.         System.out.println(" (-2,1) to (1,5) => " + d1 );
  8.  
  9.         double d2 = distance(-2,-3 , -4,4);
  10.         System.out.println(" (-2,-3) to (-4,4) => " + d2 );
  11.  
  12.         System.out.println(" (2,-3) to (-1,-2) => " + distance(2,-3,-1,-2) );
  13.  
  14.         System.out.println(" (4,5) to (4,5) => " + distance(4,5,4,5) );
  15.     }
  16.  
  17.     public static double distance( int x1, int y1, int x2, int y2 )
  18.     {
  19.         double d = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
  20.         return d;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement