Ich möchte die Entfernung zwischen zwei Punkten in Java berechnen

OK, also habe ich den größten Teil eines Programms geschrieben, mit dem ich feststellen kann, ob sich zwei Kreise überlappen.

Abgesehen von einem Problem habe ich keinerlei Probleme mit meinem Programm: Das Programm akzeptiert nicht den Code, den ich für den Abstand zwischen den beiden Mittelpunkten geschrieben habe. Ich kann die if / else-Logik herausfinden, um dem Benutzer zu sagen, was in Abhängigkeit vom Wert der Entfernung später passiert, aber ich möchte wissen, was jetzt falsch ist. Eclipse, das Programm, in dem ich programmiere, sagt mir, dass die Entfernung in ein Array aufgelöst werden soll, aber ich habe Ihnen bereits gesagt, dass es sich um ein int handelt.

Hier ist mein Code:

package circles;
import java.util.Scanner;

public class MathCircles {

    // variable for the distance between the circles' centers
    public static int distance; 

    // variable for the lengths of the radii combined
    public static int radii;

     public static void main(String[] args) {
    // Get the x-value of the center of circle one
    System.out.println("What is the x-coordinate for the center of circle one?");
    Scanner keyboard = new Scanner(System.in);
    int x1 = keyboard.nextInt();

    //Get the y-value of the center of circle one
    System.out.println("What is the y-coordinate for the center of circle one?");
    Scanner keyboard1 = new Scanner(System.in);
    int y1 = keyboard1.nextInt(); 

    //Get the radius length of circle one.
    System.out.println("How long is circle one's radius?");
    Scanner keyboard2 = new Scanner(System.in);
    int r1 = keyboard2.nextInt();

 // Get the x-value of the center of circle two.
    System.out.println("What is the x-coordinate for the center of circle two?");
    Scanner keyboard3 = new Scanner(System.in);
    int x2 = keyboard3.nextInt();

  //Get the y-value of the center of circle two.
    System.out.println("What is the y-coordinate for the center of circle two?");
    Scanner keyboard4 = new Scanner(System.in);
    int y2 = keyboard4.nextInt(); 

   //Get the radius length of circle two.
    System.out.println("How long is circle two's radius?");
    Scanner keyboard5 = new Scanner(System.in);
    int r2 = keyboard5.nextInt();

/*
 * OK, so now I have the location of the two circles' centers,
    * as well as the lengths of their radii. 
    * The circles are intersecting IF THE DISTANCE BETWEEN THE TWO CENTERS
    * IS EQUAL TO OR LESS THAN THE COMBINED LENGTHS OF THE RADII.
    * Now I need to get some math done. 
    */

//calculate the combined lengths of the radii

radii = r1 + r2; 

//calculate the distance
distance = Math.sqrt((x1-x2)(x1-x2) + (y1-y2)(y1-y2));




}

}

Antworten auf die Frage(7)

Ihre Antwort auf die Frage