Write a string program to accept a sentence from the user in uppercase. Count the number of words that start and end with a vowel. Bring all these words in the beginning of the sentence.

To learn more about string methods click the given link.
https://java4school.com/string-handling-in-java

import java.io.*;
public class VowelWord
{
    String str="",str2="",s="",st="";
    int len,count=0;
    String arr[];
    void input()throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("enter the string in upper case only");
        str=br.readLine();
        str=str.toUpperCase();
        len=str.length();
    }

    void compute()
    {
        arr=str.split("\\s+");
        int l=arr.length;
        for(int i=0;i<l;i++)
        {
            if(vowel(arr[i])==true)
            {
                count++;
                s+=(arr[i])+" ";
            }
            else
                st+=(arr[i])+ " " ;
        }
        str2=s+st;
    }

    boolean vowel(String n)
    {
        char ch=n.charAt(0);
        char ch2=n.charAt(n.length()-1);
        if((ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')&&(ch2=='A'||ch2=='E'||ch2=='I'||ch2=='O'||ch2=='U'))
            return true;
        else
            return false;
    }

    void display()
    {
        System.out.println("The entered string was: "+str);
        System.out.println("The number of words starting and ending with vowels in entered string are: "+count);
        System.out.println("The changed string is: "+str2);
    }

    public static void main()throws IOException
    {
        VowelWord obj=new VowelWord();
        obj.input();
        obj.compute();
        obj.display();
    }
}

enter the string in upper case only
MY NAME IS AESHA
The entered string was: MY NAME IS AESHA
The number of words starting and ending with vowels in entered string are: 1
The changed string is: AESHA MY NAME IS

To learn more basic java concepts watch the video.

https://youtu.be/QZKcULOC4lg

LEAVE A REPLY

Please enter your comment!
Please enter your name here