Mittelwert hinzugefügt
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user