Text only code pasted @ 10:07
on Tue, 24 Feb 09
| Revise and Submit New Paste | View as Plain Text
import java.util.Scanner; public class MyArrays { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Wie viele Elemente wollen Sie eingeben?"); int size = scanner.nextInt(); double [] liste = new double[size]; for (int i=0; i<size; i++) { System.out.print((i+1)+". Zahl: "); liste[i] = scanner.nextDouble(); } System.out.println("Minimum:"+min(liste)); System.out.println("Maximum:"+max(liste)); System.out.println("Mittelwert:"+mittel(liste)); } public static double min(double [] x) { double res = x[0]; for (int i=1; i<x.length; i++) { if (x[i] < res) res = x[i]; } return res; } public static double max(double [] x) { double res = x[0]; for (int i=1; i<x.length; i++) { if (x[i] > res) res = x[i]; } return res; } public static double mittel(double [] x) { double res = 0; for (int i=0; i<x.length; i++) { res += x[i]; } res /= x.length; return res; } }