Piglatin Form Program in Java

Piglatin Form
First, the vowels are checked and first occurring vowel in the word is found.
Then, the Piglatin word is formed by taking the substring from first vowel position and then concatinating it with the letters from first letter till the first vowel i.e. before the first vowel.Finally a string “AY” is added at the last of the word formed.

Ex:- BHARAT

  • ARAT (word from first vowel)
  • BH (word before first vowel)
  • AY

Piglatin Form = ARATBHAY

import java.util.Scanner;
public class PiglatinForm
{
    public static void main(String[] args)
    {
        String st,s1="",s2="",newSt="";
        boolean flag=false;
        Scanner sc=new Scanner(System.in);
        
        System.out.print("Enter String: ");
        st=sc.nextLine();
        
        st=st.toUpperCase();
        int l=st.length();
        for (int i = 0; i < l; i++)
        {
            char ch=st.charAt(i);
            if(flag||(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U'))
            {
                s2=s2+ch;
                flag=true;
            }
            else
            {                
                s1=s1+ch;
            }
        }
        newSt=s2+s1+"AY";
        System.out.println(newSt);
    }
}

Output:

Enter String: BHARAT
ARATBHAY
java tutorials learn java study java