Nie rozumiem o co chodzi z tym błędem, ponieważ po wpisaniu -1 program wyświetla poprawną średnią i się wyłącza.
package pl.codegym.task.task05.task0507;
/*
Średnia arytmetyczna
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int x = Integer.parseInt(reader.readLine());
int sumaLiczb = 0;
for(int a = x; true; a = a + x) {
x = Integer.parseInt(reader.readLine());
sumaLiczb++;
if (x == -1) {
double srednia = ((a + x + 1.0) / sumaLiczb);
System.out.println(srednia);
break;
}
}
}
}