Reputation: 39
For this code, I am trying to determine the distance between (x1, y1) and (x2, y2). The equation for the distance is sqrt(x2 - x1)^2 + (y2 - y1)^2.
The code looks like this,
import java.util.Scanner;
public class CoordinateGeometry {
public static void main(String [] args) {
Scanner scnr = new Scanner(System.in);
double x1;
double y1;
double x2;
double y2;
double pointsDistance;
double xDist;
double yDist;
pointsDistance = 0.0;
xDist = 0.0;
yDist = 0.0;
x1 = scnr.nextDouble();
y1 = scnr.nextDouble();
x2 = scnr.nextDouble();
y2 = scnr.nextDouble();
poinsDistance = Math.sqrt(Math.pow(x2 - x1, 2) + (Math.pow(y2 - y1, 2));
System.out.println(pointsDistance);
}
}
I keep getting an error, CoordinateGeometry.java:23: error: ')' expected poinsDistance = Math.sqrt(Math.pow(x2 - x1, 2) + (Math.pow(y2 - y1, 2)); ^ 1 error
What does this error mean?
Also an example would be, for points (1.0, 2.0) and (1.0, 5.0), pointsDistance is 3.0.
Upvotes: 1
Views: 3087
Reputation: 1530
You are missing closing )
at the end of line
poinsDistance = Math.sqrt(Math.pow(x2 - x1, 2) + (Math.pow(y2 - y1, 2)));
Or remove the opening (
before Math.pow
.
Your code should look like this:
poinsDistance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
Upvotes: 2