SEPARATE VOWEL AND CONSONANT FROM A STRING

 FOR EXAMPLE

Input: Frequency
Output: Vowel word=EUE        Consonant word=FRQNCY

SOLUTION

(RECOMMENDED TO TRY IT OWN YOUR OWN AND THEN SEE THE SOLUTION IF YOU CANNOT)

import java.util.*;

class separate

{

    void main()

    {

        Scanner ob=new Scanner(System.in);

        int l,i;

        String s,s1="",s2="";

        char ch;

        System.out.println("Enter a word");

        s=ob.nextLine();

        s=s.toUpperCase();

        l=s.length();

        for(i=0;i<l;i++)

        {

            ch=s.charAt(i);

            if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')

            {

                s1=s1+ch;

            }

            else

            {

                s2=s2+ch;

            }

        }

        System.out.println("INPUT="+s+"  Output:Vowel word="+s1+"   Consonant word:"+s2);

    }

    

}

 

ON SPOT OUTPUT SYSTEM POWERED BY



Embedding an online compiler into a website

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

It looks like you're using an ad blocker. We rely on ads to keep our site free, please whitelist us!

Click here to continue

Please whitelist our site to continue enjoying our content.

Whitelist | Close