InputOutputArithMean.java 949 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import java.util.Scanner;
  2. public class InputOutputArithMean {
  3. public static void main(String args[]) {
  4. Scanner scanner = new Scanner(System.in);
  5. String s;
  6. int i = 0;
  7. int m = 0;
  8. while (i < 1) {
  9. System.out.println("Bitte geben Sie die Anzahl der Zahlen ein, von denen Sie ein arithmetisches Mittel berechnen möchten:");
  10. try
  11. {
  12. i = scanner.nextInt();
  13. }
  14. catch(Exception ex) {
  15. System.out.println("Bitte überprüfen Sie ihre Eingabe");
  16. }
  17. }
  18. int[] arr = new int[i];
  19. for (int j = 0; j < i; j++) {
  20. System.out.println("Bitte geben Sie die " + j + "te Zahl ein:");
  21. try
  22. {
  23. /* arr[j] = scanner.nextInt(); */
  24. m += scanner.nextInt();
  25. }
  26. catch(Exception ex) {
  27. System.out.println("Bitte überprüfen Sie ihre Eingabe");
  28. }
  29. }
  30. System.out.println("keine Konvertierung, hier ist das Ergebnis: " + m / i);
  31. System.out.println(m / (double) i);
  32. }
  33. }