icse-promo

Question

Write a program that encodes a word into Piglatin. To translate word into 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 Input(1): London Sample Output(1): ONDONLAY
Sample Input(2): Olympics Sample Output(2): OLYMPICSAY

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;

public class program6 
{
    public static void main(String[] args)
    {
        int i=0;
        char ch=' ';
        String wd="",piglatin="";
        boolean vowelFound=false;

        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a String: ");
        wd = sc.next();
        wd = wd.toUpperCase();
        vowelFound = false;
        for (i = 0; i < wd.length(); i++)
        {
            ch = wd.charAt(i);
            if ((ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'))
            {
                vowelFound=true;
                piglatin =wd.substring(i);
                piglatin=piglatin+wd.substring(0,i);
                break;
            }

        }
        if(vowelFound==false)
        {
            piglatin=wd;
        }
        piglatin = piglatin + "AY";
        System.out.println("Piglatin word is " + piglatin);
    }
}


				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *