I am not able to spot the error.
package com.codegym.task.task04.task0442;
/*
Adding
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
boolean a1=true;
int b[]=new int[1000];
int sum=0;
while(a1)
{
int j=0,i,n=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a=Integer.parseInt(br.readLine());
++n;
if(a!=-1)
{
b[j]=a;
j++;
}
else if(a==-1)
{
for(i=0;i<=n;i++)
{
sum=sum+b[i];
}
sum=sum-1;
a1=false;
}
}
System.out.println(sum);
}
}