This is my code and Iam getting ArrayIndexoutofBoundsException and cant able to find where
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int sum=0,sumtotal;
Scanner sc = new Scanner(System.in);
System.out.println("Enter x");
int x = sc.nextInt();
sumtotal = (x+1)*(x+2)/2;
System.out.println("Enter the size of array");
int n = sc.nextInt();
int a[] = new int[n];
System.out.println("Enter values of array");
for(int i = 0;i<n;i++){
a[i] = sc.nextInt();
}
for(int i = 0;i<=a.length;i++)
sum = sum+a[i];
int miss = sumtotal-sum;
System.out.println(miss);
}
}
I put size of array 5 values are 1,2,4,5,6 and value of x is 5