Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class prog {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- int a = 0; //positiv counter
- int b = 0; //negativ counter
- int n = s.nextInt();
- if (n < 1 || n > 9) {
- System.out.println("Eingabe nicht möglich, bitte erneut eingeben! Es sind nur Zahlen zwischen 0 und 10 zugelassen! \n");
- n = s.nextInt();
- }
- float[] array = new float[n];
- for (int i = 0; i < array.length; i++) {
- float v = s.nextFloat();
- if (v > (-100) || v < 100) {
- if (v == 42) {
- array[i] = v;
- System.out.println("Eingabe ist 42, Durchschnitt wird berechnet \n");
- b++;
- break;
- } else {
- array[i] = v;
- if (v > 0) {
- a++;
- } else b++;
- }
- }
- System.out.println("Durschnitt wird berechnet \n");
- float x = 0;
- for (int j = 0; j < array.length; j++) {
- x += array[j];
- }
- x = x / array.length;
- System.out.println("Durchschnitt ist: " + x + "\n");
- System.out.println("Anzahl positiver Zahlen: " + a + "\n");
- System.out.println("Anzahl negativer Zahlen: " + b + "\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement