Java :: Aufgabe #35 :: Lösung #3
6 Lösungen

#35
Abstand zweier Punkte
Anfänger - Java
von Dome
- 03.01.2013 um 01:09 Uhr
Schreiben Sie ein Programm, welches den Abstand zweier Punkte berechnet. Zuvor müssen die Koordinaten beider Punkte abgefragt werden.
Konsolenausgabe:
x1:1
y1:1
x2:2
y2:2
1.4142135623730951
#3

von OlleKarre (170 Punkte)
- 30.08.2015 um 12:38 Uhr

import java.util.Scanner; class Abstand { public static void main (String [] args) { berechneAbstand(); } static Scanner eingabe () { return new Scanner (System.in); } static void berechneAbstand () { int a , b ,c ,d; double e; System.out.println("Ich bin ein Simples Java-Programm welches den Abstand zweier Punkte misst."); System.out.println("Doch dafür brauche ich die Koordinaten x1 , y1 , x2 und y2."); System.out.println("Seien Sie doch so freundlich und tippen Sie diese Koordinaten für mich ein!"); System.out.println("(Erst x1 , dann y1 , folglich x2 und zuletzt y2.)"); a = eingabe().nextInt(); b = eingabe().nextInt(); c = eingabe().nextInt(); d = eingabe().nextInt(); e = Math.sqrt( (a - c) * (a - c) + (b - d) * (b - d) ); System.out.println("x1:" + a); System.out.println("y1:" + b); System.out.println("x2:" + c); System.out.println("y2:" + d); System.out.println(e); } }
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1