ISC 2016 COMPUTER PRACTICAL QUESTION 3 SOLVED

ISC 2016 COMPUTER PRACTICAL QUESTION 3 SOLVED

ISC 2016 COMPUTER PRACTICAL QUESTION 3 SOLVED


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, following 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




Solution
import java.util.StringTokenizer;
import java.io.*;
public class ISC2016Practical3 {
    public static void main(String a[])throws IOException
    {
        int i,k ,m, n, f1, f2;
        char w1, w2;
        i = 0;
        m = 0;
        n = 0;
        f1 = f2= 0;
       
        String st, word;
        String words[] = new String[20];
        String wordWithEndBeginVowel[] = new String[10];
        String wordWithoutEndBeginVowel[] = new String[10];
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.println("Enter a sentence:");
        st=br.readLine();
        StringTokenizer st1 = new StringTokenizer(st,". , ? !");

        while(st1.hasMoreTokens())
        {
            word = st1.nextToken();
            words[i]=word;
            i++;
        }
      
        for(k=0; k<i; k++)
        {
            f1 = f2 = 0;
            switch(words[k].charAt(0))
            {
                case 'A':
                case 'a':
                case 'E':
                case 'e':
                case 'I':
                case 'i':
                case 'O':
                case 'o':
                case 'U':
                case 'u':
                f1 = 1;
               
            }
           
            switch(words[k].charAt((words[k].length())-1))
            {
                case 'A':
                case 'a':
                case 'E':
                case 'e':
                case 'I':
                case 'i':
                case 'O':
                case 'o':
                case 'U':
                case 'u':
                f2=1;
                
            }
            if(f1==1 && f2==1)
            {
                wordWithEndBeginVowel[m]=words[k];
                System.out.println(words[k]);
                m++;
               
            }
            else
            {
                wordWithoutEndBeginVowel[n]=words[k];
                n++;
            }

        }
        System.out.println("Total Words Begin and End with Vowels="+m);
        System.out.println("Words Begin and End with Vowels");
        for(i=0;i<m;i++)
            System.out.println(wordWithEndBeginVowel[i]);
        System.out.println("Words Begin and End without Vowels");
        for(i=0; i<n; i++)
            System.out.println(wordWithoutEndBeginVowel[i]);

    }
}


Sample Output:
Enter a sentence:
ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE
ANAMIKA
ARE
ANYMORE
Total Words Begin and End with Vowels=3
Words Begin and End with Vowels
ANAMIKA
ARE
ANYMORE
Words Begin and End without Vowels
AND
SUSAN
NEVER
GOING
TO
QUARREL
Enter a sentence:
HAVE A NICE DAY ANA.
A
ANA
Total Words Begin and End with Vowels=2
Words Begin and End with Vowels
A
ANA
Words Begin and End without Vowels
HAVE
NICE
DAY

MORE ISC COMPUTER SCIENCE PROGRAM

Circular prime number program in java





SHARE THIS
Previous Post
Next Post