Text only code pasted @ 10:07 on Tue, 24 Feb 09 | Revise and Submit New Paste | View as Plain Text
  1. import java.util.Scanner;
  2. public class MyArrays {
  3. public static void main(String[] args) {
  4. Scanner scanner = new Scanner(System.in);
  5. System.out.println("Wie viele Elemente wollen Sie eingeben?");
  6. int size = scanner.nextInt();
  7. double [] liste = new double[size];
  8. for (int i=0; i<size; i++) {
  9. System.out.print((i+1)+". Zahl: ");
  10. liste[i] = scanner.nextDouble();
  11. }
  12. System.out.println("Minimum:"+min(liste));
  13. System.out.println("Maximum:"+max(liste));
  14. System.out.println("Mittelwert:"+mittel(liste));
  15. }
  16. public static double min(double [] x) {
  17. double res = x[0];
  18. for (int i=1; i<x.length; i++) {
  19. if (x[i] < res)
  20. res = x[i];
  21. }
  22. return res;
  23. }
  24. public static double max(double [] x) {
  25. double res = x[0];
  26. for (int i=1; i<x.length; i++) {
  27. if (x[i] > res)
  28. res = x[i];
  29. }
  30. return res;
  31. }
  32. public static double mittel(double [] x) {
  33. double res = 0;
  34. for (int i=0; i<x.length; i++) {
  35. res += x[i];
  36. }
  37. res /= x.length;
  38. return res;
  39. }
  40. }