When I enter 1,2,2,4,5, -1, it doesn't work. It gives me 2.0 instead of 2.8 for some reason :(
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 input = 0;
int log = 0;
int count = 0;
while (input != -1) {
input = Integer.parseInt(reader.readLine());
if (input != -1) {
log += input;
count++;
}
else if (input == -1) {
double result = (double)(log / count);
System.out.println(result);
break;
}
}
}
}