Created
December 30, 2014 23:49
-
-
Save roma-sck/d4551ca8592e3f1f7a5e to your computer and use it in GitHub Desktop.
com.javarush.test.level06.lesson08.task03
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level06.lesson08.task03; | |
/* Класс Util | |
Реализовать статический метод double getDistance(x1, y1, x2, y2). Он должен вычислять расстояние между точками. | |
Используй метод double Math.sqrt(double a), который вычисляет квадратный корень переданного параметра | |
*/ | |
public class Util | |
{ | |
public static double getDistance(int x1, int y1, int x2, int y2) | |
{ | |
double result = 0; | |
// расстояние между точками,определяется из условия d2 = (х2— х1)2 + (y2— y1)2. | |
// Отсюда d = \/(х2— х1)2 + (y2— y1)2 | |
result = Math.sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment