I am trying to make a cocktail sort but I am getting an out of bound exception at the line if (a[i] > a[i + 1]) and I'm not sure why.
Here is the full code. Sorry if this is completely wrong.
import java.util.Arrays;
import java.util.Scanner;
public class Cocktail 
{
public static void main(String[] args) 
{
    Scanner input = new Scanner(System.in);
    int count = 0;
    boolean switched = true;
    int[]a = new int[10];
    for (int i = 0; i < a.length; i++)
    {
        int value = input.nextInt();
        a[i] = value;
    }
    System.out.println(a[0]);
    while (switched == true)
    {
        switched = false;
        for (int i = 0; i < a.length; i++)
        {
            if (a[i] > a[i + 1]) 
            {
                int temp = a[i];
                a[i] = a[i + 1];
                a[i + 1] = temp;
                count++;
                switched = true;
            }
        }
        for (int i = a.length; i >= 0; i++)
        {
            if (a[i] > a[i + 1]) 
            {
                int temp = a[i];
                a[i] = a[i + 1];
                a[i + 1] = temp;
                count++;
                switched = true;
            }
        }
        if (switched == false)
        {
            System.out.println(count);
        }
    }
}
}
 
    
