Programming Examples

Java program to encodes a word into Piglatin


Write a program that encodes a word into Piglatin. To translate word into a Piglatin word, convert the word into uppercase and then place the first vowel of the original word as the start of the new word along with the remaining alphabets. The alphabets present before the vowel being shifted towards the end followed by “AY”.

Sample 1:

Input  : London,

Output : ONDONLAY

Sample 2:

Input : Olympics,

Output : OLYMPICSAY

Solution:
import java.util.*;
class PigLatin
{    
    public static void main(String arr[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter Any String ");
        String str1=sc.nextLine();        
        String str2="",str3;
        str1=str1.toUpperCase();
        str3=str1;
        for(int a=0;a<str1.length();a++)
        {
            if(str1.charAt(a)=='A'||str1.charAt(a)=='E'||str1.charAt(a)=='I'||str1.charAt(a)=='O'||str1.charAt(a)=='U')
            {
                str2=str1.substring(0,a);
                str3=str1.substring(a,str1.length());
               // System.out.println("Str 2 : "+str2);
               // System.out.println("Str 3 : "+str3);
                break;
            } 
        }
        str1=str3+str2+"AY";
        System.out.println("PigLating Word is : "+str1);
    }
}
Output

Enter Any String 

landon

PigLating Word is : ANDONLAY

Enter Any String 

amit

PigLating Word is : AMITAY

Enter Any String 

crwth

PigLating Word is : CRWTHAY

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz