Name with A Program in Java

Define a class to declare an array to accept and store ten words. Display only those words which begin with the letter ‘A’ or ‘a’ and also end with the letter ‘A’ or ‘a’ [10]
EXAMPLE
Input: Hari, Anita. Akash, Amrita, Alina, Devi, Rishab, Jolin, Farha, AMITHA
Output:
Anita
Amrita
Alina
AMITHA
Farha


import java.util.Scanner;
public class NameWithA
{
    public static void main(String[] args)
    {
        String names[] = new String[10];
        Scanner sc = new Scanner(System.in);
        int l = names.length;
        System.out.println("Enter 10 name:");
        for (int i = 0; i < l; i++)
        {
             names[i]=sc.nextLine();
        }
        System.out.println("Names are:-");
        for (int i = 0; i < l - 1; i++)
        {
            int lastIndex = names[i].length() - 1;
            if(names[i].charAt(0)=='a'||names[i].charAt(0)=='A'||names[i].charAt(lastIndex)=='a'||names[i].charAt(lastIndex)=='A')
            {
                System.out.println(names[i]);
            }
        }
    }
}

Output:

Enter 10 name:
Hari
Anita
Akash
Amrita
Alina
Devi
Rishab
Jolin
Farha
AMITHA
Names are:-
Anita
Akash
Amrita
Alina
Farha