Hallo, gibt man in meinem Code die ersten zwei Integers ein, kommt der richtige Mittelwert raus. Gebe ich mehr ein, stimmt der Mittelwert nicht mehr:( Hat jemand einen Tipp? Danke im Voraus!
Hi, as long as only two Integers are typed in, the result is correct. With more than two integers the aritmethic mean given out is wrong. Does anybody havee got an idea/hint? Thank you in advace!
package de.codegym.task.task05.task0507;
/*
Arithmetisches Mittel
*/
import java.util.*;
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//schreib hier deinen Code
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int value;
double sum = 0;
value = Integer.parseInt(reader.readLine());
int count = 1;
while (value != -1){
sum = ((sum + value)/(count));
value = Integer.parseInt(reader.readLine());
count++;
}
System.out.println( "Sum of the integers: " + sum );
}
}