[Question 3] ISC 2016 Computer Practical Paper Solved – Words Beginning and Ending with Vowel.

Question 3:

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 with the sample data and some random data:
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 VOWEL= 0
LOOK BEFORE YOU LEAP
Example 4
INPUT: HOW ARE YOU@

OUTPUT: INVALID INPUT



SOURCE CODE


import java.io.*;
import java.util.*;
public class ISC2016_Ques3
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter a sentence in upper case   :");
        String str=sc.nextLine();
        int l=str.length();
        StringTokenizer s=new StringTokenizer(str," .?!");
        int number=s.countTokens();
        String st="",st2="",word="";int count=0;
        char ch=str.charAt(l-1);
        if(ch=='.'|| ch=='?'|| ch=='!')
        {
            for(int i=1;i<=number;i++)
            {
                word=s.nextToken();
                char ch1=word.charAt(0);
                char ch2=word.charAt(word.length()-1);
                if((ch1=='A' || ch1=='E' || ch1=='I' || ch1=='O' || ch1=='U'))
                {
                    if(ch2=='A' || ch2=='E' || ch2=='I' || ch2=='O' || ch2=='U')
                    {
                        count++;
                        st=st+word+" ";
                    }                   
                }
                else
                    st2=st2+word+" ";
            }
            System.out.println("OUTPUT");
            System.out.println("Number of words beginning and ending with a vowel = "+count);
            System.out.println(st+st2);
        }
        else
        {
            System.out.print("INVALID INPUT");
        }
    }
}


OUTPUT



Comments

Popular posts from this blog

[Question 3] ISC 2017 Computer Practical Paper Solved – Caesar Cipher.

Pattern of your own name.

Designing Patterns - Print 'Z'.