Saturday , 24 June 2017
Home » Class 12 » [Question 3] ISC 2016 Computer Practical Paper Solved – Words Beginning and Ending with Vowel

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

Click here to download the complete ISC 2016 Computer Science Paper 2 (Practical).

Question:

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

Programming Code:

/**
 * The class ISC2016_Q3 inputs a sentence, and prints and counts the words
 * beginning and ending with a vowel, before other words
 * @author : www.guideforschool.com
 * @Program Type : BlueJ Program - Java
 * @Question Year : ISC Practical 2016 Question 3
 */

import java.util.*;
class ISC2016_Q3
{
    boolean isVowel(String w) // Function to check if a word begins and ends with a vowel or not
    {
        int l = w.length();
        char ch1 = w.charAt(0); // Storing the first character
        char ch2 = w.charAt(l-1); // Storing the last character
        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;
        }
    }

    public static void main(String args[])
    {
        ISC2016_Q3 ob = new ISC2016_Q3();
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a sentence : ");
        String s = sc.nextLine();
        s = s.toUpperCase();
        int l = s.length();
        char last = s.charAt(l-1); // Extracting the last character

        /* Checking whether the sentence ends with '.' or '?' or not */
        if(last != '.' && last != '?' && last != '!')
        {
            System.out.println("Invalid Input. End a sentence with either '.', '?' or '!' only");
        }
        else
        {
            StringTokenizer str = new StringTokenizer(s," .?!");
            int x = str.countTokens();
            int c = 0;
            String w = "", a = "", b = "";

            for(int i=1; i<=x; i++)
            {
                w = str.nextToken(); // Extracting words and saving them in w

                if(ob.isVowel(w))
                {
                    c++; // Counting all words beginning and ending with a vowel
                    a = a + w + " "; // Saving all words beginning and ending with a vowel in variable 'a'
                }
                else
                    b = b + w + " "; // Saving all other words in variable 'b'   
            }
            System.out.println("OUTPUT : \nNUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = " + c);
            System.out.println(a+b);

        }
    }
}

Output:

Enter a sentence : 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

Check Also

[Question 2] ISC 2017 Computer Practical Paper Solved – Quiz Result

Solution of Program 2 of ISC 2017 Computer Science Paper 2 (Practical) Exam. Java program to input the answers of each participant row-wise and calculate their marks

Leave a Reply

Your email address will not be published. Required fields are marked *