What is the correct way to calculate the distance between two points using the Java distance formula, and how can I fix my current implementation?

To keep your main logic clean and reusable, extract the distance formula into a method:

public static double getDistance(int x1, int y1, int x2, int y2) {
    return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
}

Then call it like this:

double distance = getDistance(x1, y1, x2, y2);