Display and count word which starting and ending with vowel (Problem_6) School

 package School;

import java.util.*;

class Program_6 {

    public static void main(String args[]) {

        Scanner in = new Scanner(System.in);

        System.out.println("Enter Sentence");

        String sentence = in.nextLine();

        sentence = sentence.toUpperCase();

        String check[] = new String[5];

        check[0] = "A";

        check[1] = "E";

        check[2] = "I";

        check[3] = "O";

        check[4] = "U";

        String Temp = "";

        int c = 0;

        if (sentence.endsWith(".") || sentence.endsWith("!") || sentence.endsWith("?")) {

            sentence = sentence.substring(0, sentence.length() - 1);

            StringTokenizer st = new StringTokenizer(sentence);

            while (st.hasMoreTokens()) {

                Temp = st.nextToken();

                for (int i = 0; i < 5; i++) {

                    for (int j = 0; j < 5; j++) {

                        if (Temp.startsWith(check[j]) && Temp.endsWith(check[i])) {

                            c++;

                            System.out.println(Temp);

                        }

                    }

                }

            }

            if (c == 0) {

                System.out.println("No word Available Starting with Vowel");

            } else {

                System.out.println("Number of words which starts and ends with vowel are:" + c);

            }

        } else {

            System.out.println("Invalid Input");

        }

    }

}


Comments