Friday, 18 June 2021

Piglatin Word – String Java Program


Sample Input (1) : London,
Sample Output (1) : ONDONLAY

Sample Input (2) : Olympics,
Sample Output (2) : OLYMPICSAY


import java.util.Scanner;

public class Piglatin_Tridib
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a word");
String s = in.nextLine();

s = s.toUpperCase(); //to convert the word in UpperCase

//to find the position of first vowel
int i;
for(i=0; i<s.length(); i++)
{
char ch = s.charAt(i);
if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
break; //means vowel is found at i
}

String f = s.substring(i) + s.substring(0,i) + "AY";
System.out.println(f);
}
}


Output:




No comments:

Post a Comment