Could someone please have a look? Don't know why this code is not working - the result is always wrong (works only for input -100, 0, 100 and -1, output 0.0).
package pl.codegym.task.task05.task0507;
/*
Średnia arytmetyczna
*/
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
//tutaj wpisz swój kod
Scanner scanner = new Scanner(System.in);
int sum = 0;
int count = 0;
while (true) {
int number = scanner.nextInt();
sum = sum + number;
count += 1;
if (number == -1)
break;
}
double avg = sum / count;
System.out.println(avg);
}
}