Back to Tutorials
Solved ProgramsISCClass 12Computer Science

Words that start and end with a vowel program: ISC 2016 program

Write a program to accept a sentence which may be terminated by either’.’, ‘?’or’!’ only. The words may be separated by more than one blank space and are in UPPER CASE.

Trushna Tejwani4 March 2021
Solved Programs

Watch java videos

words that start and end with a vowel program.

Write a program to accept a sentence which may be terminated by either’.’, ‘?’or’!’ only. The words may be separated by more than one blank space and are in UPPER CASE.

Perform the following tasks:

(a) Find the number of words beginning and ending with a vowel.

(b) Place the words which begin and end with a vowel at the beginning, followed by the remaining words as they occur in the sentence.

Test your program for words that start and end with a vowel with the sample data and some random data:
words that start and end with a vowel

Example 1

INPUT: ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE.

OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL= 3

ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL

Example 2

INPUT: YOU MUST AIM TO BE A BETTER PERSON TOMORROW THAN YOU ARE TODAY.

OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL= 2

A ARE YOU MUST AIM TO BE BETTER PERSON TOMORROW THAN YOU TODAY

Example 3

INPUT: LOOK BEFORE YOU LEAP.

OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A OWEL= 0

LOOK BEFORE YOU LEAP

Example 4

INPUT: HOW ARE YOU@

OUTPUT: INVALID INPUT

import java.util.*;
public class StartEndVowel
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the String");
        String str=sc.nextLine().toUpperCase();//taking input and converting to Uppercase
        int len=str.length();
        char ch=str.charAt(len-1);//last character in the string

        if(ch=='.'||ch=='!'||ch=='?')//checking if the string ends with valid symbols
        {
            str=str.substring(0,len-1);//removing the full stop or exclamation mark
            String arr[]=str.split(" ");
            String vowel="";//for the words that start and end with vowels
            String notvowel="";//for other words
            int count=0;//to count the number of words that start and end with vowels

            for(int i=0;i<arr.length;i++)
            {
                String temp=arr[i];
                int l=temp.length();

                char start=temp.charAt(0);
                char end=temp.charAt(l-1);
                if(start=='A'||start=='E'||start=='I'||start=='O'||start=='U')//checking
                {
                    if(end=='A'||end=='E'||end=='I'||end=='O'||end=='U')
                    {
                        vowel+=temp+" ";
                        count++;
                    }
                    else
                        notvowel+=temp+" ";//here the word does not end with vowel
                }
                else
                    notvowel+=temp+" ";//neither starts nor ends with vowels
            }
            String result=vowel+notvowel;//just concatenating both strings
            System.out.println("Words starting and ending with vowels are "+count);
            System.out.println(result);
        }
        else
            System.out.println("INVALID INPUT");
    }
}

Download free Sample papers