CodeHub Menu
Home Exercise Practice About Download Portfolio Play Games NEW Privacy Policy Terms Contact
Login / Register

Names that begin and end with letter A are

JAVA November 19, 2025 4 views 0 likes
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'.
EXAMPLE :
Input : Hari, Anita, Akash, Amrita, Alina, Devi Rishab, John, Farha, AMITHA
Output: Anita
Amrita
Alina
AMITHA

Answer:

KboatWords - Java Code

KboatWords - Java Code


import java.util.Scanner;

public class KboatWords
{
    public static void main(String args[]) 
    {
        Scanner in = new Scanner(System.in);
        String names[] = new String[10];
        int l = names.length;
        System.out.println("Enter 10 names : ");
        
        for (int i = 0; i < l; i++) 
        {
            names[i] = in.nextLine();
        }
        
        System.out.println("Names that begin and end with letter A are:");

        for(int i = 0; i < l; i++)
        {
            String str = names[i];
            int len = str.length();
            char begin = Character.toUpperCase(str.charAt(0));
            char end = Character.toUpperCase(str.charAt(len - 1));
            
            if (begin == 'A' && end == 'A') {
                System.out.println(str);
            }
        }
    }
}

OUTPUT:

Kboat Words - Start & End With A

Enter 10 Names

4 views 0 likes
Total visits: 2,089 • Unique visitors: 1,285