package com.javarush.test.level06.lesson08.task03;

/ Class Util Implement a static method double getDistance(x1, y1, x2, y2). It should calculate the distance between points. Use the method double Math.sqrt(double a) to calculate the square root of the parameter passed. /

public class Util
{
    public static double getDistance(int x1, int y1, int x2, int y2)
    {
        //add your code here
        int xTotalSq = (x1+x2)*(x1+x2);
        int yTotalSq = (y1+y2)*(y1+y2);
        int distSq = xTotalSq + yTotalSq;
        double dist = (double) distSq;
        return Math.sqrt(distSq);

    }
}

I know that this code works just fine. but it doesn't pass the test. Can some one give tips what can be wrong?

asked 20 Mar, 08:29

Vagon's gravatar image

Vagon
11
accept rate: 0%


nevermind. I got this.

link

answered 20 Mar, 08:42

Vagon's gravatar image

Vagon
11
accept rate: 0%

public class Util { public static double getDistance(int x1, int y1, int x2, int y2) { double c = (((x2 - x1)(x2 - x1)) + ((y2 - y1)(y2 - y1))); double a = Math.sqrt(c); return a;//add your code here

}

}

link

answered 11 Sep, 13:40

Vladymyr's gravatar image

Vladymyr
1
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×69
×53
×8

Asked: 20 Mar, 08:29

Seen: 225 times

Last updated: 11 Sep, 13:40