Wednesday, October 24, 2018

BlueJ Program On Number Of Words Beginning And Ending With A Vowel In A Sentence




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.

import java.io.*;
import java.util.*;

class Prog3
{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   String str;
   StringTokenizer st;
   String s,sarr[];
   int index=0;
    public void show()throws Exception
   {
    System.out.println("Enter the sentence:");
    str=br.readLine().toUpperCase();
    st=new StringTokenizer(str," .,?!");
srr=new String [st.tokenCounts()];
    while(st.hasMoreTokens())
    {
        s=st.nextToken();
        if(vowel(s))
        sarr[index++]=s;
    }
while(!st.hasMoreTokens())
    {
        s=st.nextToken();
        if(vowel(s))
        sarr[index++]=s;
    }

   for(int i=0;i< index;i++)
    System.out.println(sarr[i]);
    }
   
    private boolean vowel(String s1)
    {
         int x;
         len=s1.length();
         x=len-1;
boolean bool=false;
         switch(s1.charAt(0))
{
case ‘A’:
case ‘E’:
case ‘I’:
case ‘O’:
case ‘U’:
bool=true;
}

 switch(s1.charAt(x))
{
case ‘A’:
case ‘E’:
case ‘I’:
case ‘O’:
case ‘U’:
bool=true;
}
return bool;
}

      
     public static void main(String args[]) throws Exception
     {
      Prog3 ob=new Prog3();
      ob.show();
      }
      }


Related Post: BlueJ Programs on String/Sentence

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner