Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class prog {
  4.  
  5. public static void main(String[] args) {
  6. Scanner s = new Scanner(System.in);
  7. int a = 0; //positiv counter
  8. int b = 0; //negativ counter
  9. int n = s.nextInt();
  10. if (n < 1 || n > 9) {
  11. System.out.println("Eingabe nicht möglich, bitte erneut eingeben! Es sind nur Zahlen zwischen 0 und 10 zugelassen! \n");
  12. n = s.nextInt();
  13. }
  14. float[] array = new float[n];
  15. for (int i = 0; i < array.length; i++) {
  16. float v = s.nextFloat();
  17. if (v > (-100) || v < 100) {
  18. if (v == 42) {
  19. array[i] = v;
  20. System.out.println("Eingabe ist 42, Durchschnitt wird berechnet \n");
  21. b++;
  22. break;
  23. } else {
  24. array[i] = v;
  25. if (v > 0) {
  26. a++;
  27. } else b++;
  28. }
  29. }
  30. System.out.println("Durschnitt wird berechnet \n");
  31. float x = 0;
  32. for (int j = 0; j < array.length; j++) {
  33. x += array[j];
  34. }
  35. x = x / array.length;
  36. System.out.println("Durchschnitt ist: " + x + "\n");
  37. System.out.println("Anzahl positiver Zahlen: " + a + "\n");
  38. System.out.println("Anzahl negativer Zahlen: " + b + "\n");
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement