The code its working, but it can't be validate by the last condition (The displayed result should match the task conditions for any input data.)
I dont understand where is the problem. i just notice that if you start with -1, the result is NaN. I dont know what this mean actually.
package com.codegym.task.task05.task0507;
/*
Arithmetic mean
*/
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));
double x = 0;
int count = 0;
while ( true ) {
double a = Double.parseDouble(reader.readLine());
if (a != -1)
x = x+a;
if (a != -1)
count++;
if (a == -1)
break;
}
if (x <= 0)
System.out.println(x);
else
System.out.println((double)x/count);
}
}