Why does an error occur?
package com.codegym.task.task05.task0507;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Solution {
    public static void main(String[] args) throws Exception {

            int n = 0;
            int count = 0;
            double result;

        for (int i = 1; ; i++) {
            count++;
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(reader.readLine());

            if (a != -1){
            n = n + a;
            }

            else if (a == -1){
                result = n/count;
               System.out.println(n);
               break;
            }
            }

    }
}