I've tried various different ways, but I just don't understand what's wrong. The program calculates the result incorrectly, but compiles and passes the "if -1 entered the program should terminate correctly" requirement.
package com.codegym.task.task05.task0507;
/*
Arithmetic mean
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int count = 0;
int total = 0;
double mean;
while(true) {
int number = Integer.parseInt(reader.readLine());
if (number == -1) {
break;
}
count++;
total += number;
}
if (count != 0) {
mean = (double)total / (double)count;
}
mean = 0;
System.out.println(mean);
}
}