Schreiben Sie ein Programm zur Bestimmung des Abstandes zweier Punkte P1(x1 , y1) und P2(x2 , y2) nach der Formel

Lösung
import java.util.Scanner; // Scanner für die Eingabe von Werten
public class Aufgabe3
{
public static void main(String[] args)
{
// Variablen Deklaration
double x1, y1, x2, y2;
Scanner scnEingabe = new Scanner(System.in);
// Variablen Initialisierung
System.out.println("Übungsaufgabe 3: Abstand von zwei Punkten");
System.out.println("Bitte Koordinaten von P1(x1, y1) und P2 eingeben");
System.out.print("x1 = ");
x1 = scnEingabe.nextDouble();
System.out.print("y1 = ");
y1 = scnEingabe.nextDouble();
System.out.print("x2 = ");
x2 = scnEingabe.nextDouble();
System.out.print("y2 = ");
y2 = scnEingabe.nextDouble();
// Berechnung und Ausgabe des Ergebnisses
System.out.println();
System.out.println("Abstand der beiden Punkte: "
+ Math.sqrt(Math.pow((x2-x1), 2)+Math.pow((y2-y1), 2)));
} // end main
} // end class

