Hello!
Why the arithmetic mean result is not correct in my code?
Thanks a lot!
package com.codegym.task.task05.task0507;
/*
Arithmetic mean
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
int sum = 0;
int count = 0;
int number = Integer.parseInt(reader.readLine());
while (number != -1) {
double avg = 0;
number = Integer.parseInt(reader.readLine());
sum += number;
count++;
if (number == -1) {
avg = sum / count;
System.out.println(avg);
break;
}
}
}
}

package com.codegym.task.task05.task0507;
/*
Arithmetic mean
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
int sum = 0;
int count = 0;
int number = Integer.parseInt(reader.readLine());
while (number != -1) {
double avg = 0;
number = Integer.parseInt(reader.readLine());
sum += number;
count++;
if (number == -1) {
avg = sum / count;
System.out.println(avg);
break;
}
}
}
}