JAVA Practical ISC 2016 Solve - Start and End Vowel
softetechnologies
10-08-2019    209 times
JAVA Practical ISC 2016 Solve Vowel

This program is selected from ISC 2016 Computer Science or Class 12 practical paper.

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 I UPPER CASE.

Perform the following tasks:

  1. Find the numbers of words beginning and ending with a vowel.
  2. Place the words which begin and end with a vowel at the beginning, followed by the remaining words as they occur in the sentence.

Example 1:

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

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

ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL.

import java.util.*;
public class BegEndVowel
{
    public static void main(String []args)
    {
        Scanner sc=new Scanner(System.in);
        BegEndVowel bev=new BegEndVowel();
        System.out.print("Enter Your String : ");
        String str=sc.nextLine();
        int len=str.length();
        char ch=str.charAt(len-1);
        String res="";
        String temp="";
        if(ch=='.' || ch=='?' || ch=='!')
        {
            String []words=str.substring(0,len-1).split(" ");
            int c=0;
            for(int i=0;i<words.length;i++)
            {
                if(words[i].length()>0)
                {
                    if(bev.checkword(words[i]))
                    {
                        c++;
                        res += words[i] + " ";
                    }
                    else
                    {
                        temp += words[i] + " ";
                    }
                }   
             }
             System.out.println("NUMBER OF WORDS BEGINNING AND ENDING WITH VOWEL = " + c);
             res = (res + temp).trim();
             System.out.println(res);
        }
        else
        {
           System.out.println("INVALID INPUT");
        }
    }
    boolean checkword(String s)
    {
        int len=s.length();
        char ch1=s.charAt(0);
        char ch2=s.charAt(len-1);
        if((ch1=='A' || ch1=='E' || ch1=='I' || ch1=='O' || ch1=='U') && (ch2=='A' || ch2=='E' || ch2=='I' || ch2=='O' || ch2=='U'))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
Private Teacher

Example 1

Enter Your String : ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE.
NUMBER OF WORDS BEGINNING AND ENDING WITH VOWEL = 3
ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL

Example 2

Enter Your String : YOU MUST AIM TO BE A BETTER PERSON TOMORROW THAN YOU ARE TODAY.
NUMBER OF WORDS BEGINNING AND ENDING WITH VOWEL = 2
A ARE YOU MUST AIM TO BE BETTER PERSON TOMORROW THAN YOU TODAY

Example 3

Enter Your String : LOOK BEFORE YOU LEAP.
NUMBER OF WORDS BEGINNING AND ENDING WITH VOWEL = 0
LOOK BEFORE YOU LEAP

Example 4

Enter Your String : HOW ARE YOU@
INVALID INPUT

softetechnologies
softetechnologies
    Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
    Related Post
  Query About the post