package com.codegym.task.task06.task0609;
/*
Distance between two points
*/
public class Util {
public static double getDistance(int x1, int y1, int x2, int y2) {
int a = (x2 - x1);
int b = (y2 - y1);
int p = a*a + b*b;
double s = Math.sqrt(double p);
return s;
}
public static void main(String[] args) {
}
}
how to resolve this?
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Xuhaib
9 November 2018, 14:17
a*a is not equal to a^2 (raise to the power 2). Modify your formula to something like
double a =Math.sqrt((x2-x1)^2+(y2-y1)^2);
-2
Nehal Abubakar
1 October 2018, 20:09
Can any help me out with the same problem.
0
Artem Divertitto Senior Android Developer at United Tech
21 August 2018, 08:49
If you want to send variable to method, use only name, like Math.sqrt(p);
+8