Return the distance from the point (x1, y1) to the point (x2, y2). You may use Math.sqrt().
distance(1, 2, 4, 6) returns 5.0.
8 strips: L1 to L8
return dist; L1int dy = y2 - y1; L2double dist = Math.sqrt(squares); L3double dist = Math.pow(squares, 2); L4int dx = x2 - x1; L5int squares = dx * dx + dy * dy; L6public static double distance(int x1, int y1, int x2, int y2) { L7} L8Order: L7, L5, L2, L6, L3, L1, L8. Extra: L4
Lines with the same mark can go in either order.
public static double distance(int x1, int y1, int x2, int y2) {
int dx = x2 - x1;
int dy = y2 - y1;
int squares = dx * dx + dy * dy;
double dist = Math.sqrt(squares);
return dist;
} Extra strip: double dist = Math.pow(squares, 2);. Math.pow(squares, 2) squares the number again. The distance is the square root, Math.sqrt(squares).