Mittelwert hinzugefügt

This commit is contained in:
Joel Baldauf
2020-12-18 10:39:46 +01:00
parent f464f88a6f
commit 7da8a1f47c
5 changed files with 77 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
import java.util.Scanner; //1
public class Mittelwert {
public static double verarbeitung(double pZahl1, double pZahl2) {
double ergebnis = (pZahl1 + pZahl2) / 2.0;
return ergebnis;
}
public static void main(String[] args) {
Scanner meinScanner = new Scanner(System.in); //2
// Deklaration der Variablen
double zahl1;
double zahl2;
double mittelwert;
// (E) "Eingabe"
// Werte für x und y festlegen:
System.out.print("Wie lautet der erste Wert? ");
zahl1 = meinScanner.nextDouble(); //3
System.out.print("Wie lautet der zweite Wert? ");
zahl2 = meinScanner.nextDouble(); //3
// (V) Verarbeitung
// Mittelwert von x und y berechnen:
// ================================
// mittelwert = (zahl1 + zahl2) / 2.0;
mittelwert = verarbeitung(zahl1, zahl2);
// (A) Ausgabe
// Ergebnis auf der Konsole ausgeben:
// =================================
System.out.printf("Der Mittelwert von %.2f und %.2f ist %.2f\n", zahl1, zahl2, mittelwert);
}
}