Program 93, Distance Formula

Code

   ///Name: Stella Koliavas
   ///Period: 5
   ///File Name: Distance.java
   ///Date Finshed: 3/11/16
   
   public class Distance
   {
   public static void main( String[] args )
   {
		// test the formula a bit
		double d1 = distance(-2,1 , 1,5);
		System.out.println(" (-2,1) to (1,5) => " + d1 );
		
		double d2 = distance(-2,-3 , -4,4);
		System.out.println(" (-2,-3) to (-4,4) => " + d2 );
		
		System.out.println(" (2,-3) to (-1,-2) => " + distance(2,-3,-1,-2) );
		
		System.out.println(" (4,5) to (4,5) => " + distance(4,5,4,5) );
		}
		
		public static double distance( double x1, double y1, double x2, double y2 )
		{
		 double distance = Math.sqrt((x1-x2)*(x1-x2)+ (y1-y2)*(y1-y2));
        
         return distance;
         }
         }

        
        
        


        
    

Picture of the output

Program 93