import java.util.Scanner; import java.io.File; int zaehleWerte(String dateiname) throws Exception { Scanner sc = new Scanner(new File(dateiname), "UTF-8"); int anzahl = 0; while (sc.hasNextLine()) { String zeile = sc.nextLine(); if (!zeile.isBlank()) { anzahl = anzahl + 1; } } sc.close(); return anzahl; } int[] ladeMesswerte(String dateiname) throws Exception { int anzahl = zaehleWerte(dateiname); int[] werte = new int[anzahl]; Scanner sc = new Scanner(new File(dateiname), "UTF-8"); int index = 0; while (sc.hasNextLine()) { String zeile = sc.nextLine(); if (!zeile.isBlank()) { werte[index] = Integer.parseInt(zeile); index = index + 1; } } sc.close(); return werte; } void main() throws Exception { int[] werte = ladeMesswerte("messwerte.txt"); if (werte.length >= 1) { Statistik s = new Statistik(); int summe = s.berechneSumme(werte); double durchschnitt = s.berechneDurchschnitt(werte); int min = s.findeMinimum(werte); int max = s.findeMaximum(werte); int ueberSchnitt = s.zaehleUeberDurchschnitt(werte, durchschnitt); int spannweite = s.berechneSpannweite(werte); IO.println("Spannweite: " + spannweite); IO.println("Anzahl: " + werte.length); IO.println("Summe: " + summe); IO.println("Durchschnitt: " + durchschnitt); IO.println("Minimum: " + min); IO.println("Maximum: " + max); IO.println("Ueber Durchschnitt: " + ueberSchnitt); } else { IO.println("Keine Daten gefunden."); } }