Arrange Words

Program to accept a sentence which is terminated by ‘.’ or ‘?’ or ‘!’ only. Check for words starting and ending with vowels and arrange then at the start of the whole sentence. Also show the frequency of words starting and ending with vowels.

Note: The words may be separated by more than one space but the program should remove it.

Example: “Susan and    Anamika are never    going to quarrel again.”. The program is expected to generate new sentence that is “Anamika are Susan and never going to quarrel again.” where frequency of words starting and ending with vowels is 2.

Java
import java.util.*;
public class ArrangeWord
{
    public static void main(String args[])
    {
        String str="",nstr="",vstr="",wrd="";
        char ch=' ',sCh=' ',eCh=' ';
        int l=0,f=0;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter a sentence ending with '.' or '?' or '!'");
        str=sc.nextLine();
        str=str.trim();
        l=str.length();
        ch=str.charAt(l-1);
        if(!(ch=='.'||ch=='?'||ch=='!'))
        {
            System.out.println("Error! Sentence must be terminated by punctuation");
            System.exit(1);
        }
        for(int i=0;i<l;i++)
        {
            ch=str.charAt(i);
            if(ch==' '||ch=='.'||ch=='?'||ch=='!')
            {
                if(wrd.equals(""))
                {
                    continue;
                }
                sCh=wrd.charAt(0);
                eCh=wrd.charAt(wrd.length()-1);
                if((sCh=='a'||sCh=='e'||sCh=='i'||sCh=='o'||sCh=='u'||sCh=='A'||sCh=='E'||sCh=='I'||sCh=='O'||sCh=='U')
                 &&(eCh=='a'||eCh=='e'||eCh=='i'||eCh=='o'||eCh=='u'||eCh=='A'||eCh=='E'||eCh=='I'||eCh=='O'||eCh=='U'))
                {
                    vstr=vstr+wrd+" ";
                    f++;
                }
                else
                {
                    nstr=nstr+wrd+" ";
                }
                wrd="";
            }
            else
            {
                wrd=wrd+ch;
            }
        }
        nstr=vstr+nstr;
        System.out.println("Frequency of words starting and ending with vowels: "+f);
        System.out.println("New string: "+nstr);
    }
}
Java